Hi Alec,

Am Freitag, den 09.04.2010, 16:52 -0700 schrieb Alec Mihailovs:
> For example,
> 
> var('t R_u c')
> map(function,('R_b', 'psi', 'm_z'))
> r = R_b(t)*sin(psi(t))
> z = R_b(t)*cos(psi(t))+m_z(t)
> Dr, Dz = r.diff(t), z.diff(t)
> v=vector([Dr,Dz]) * vector([cos(psi(t)),sin(psi(t))])
> w=v.simplify_trig()
> w.substitute_function(m_z,lambda t:-sqrt(R_b(t)^2-R_u^2))
> 
> 2*sin(psi(t))*cos(psi(t))*D[0](R_b)(t) -
> sin(psi(t))*R_b(t)*D[0](R_b)(t)/sqrt(-R_u^2 + R_b(t)^2) -
> (2*sin(psi(t))^2*R_b(t) - R_b(t))*D[0](psi)(t)
> 
> Alec Mihailovs

thanks for your solution, of course it works well.  Besides it's a nice
lesson in typing economics in Sage :-)

I tried to understand my mistake and I realised that I have difficulties
to distinguish between symbolic expressions and functions and when to
use either.  In the tutorial there is a section "Some Common Issues with
Functions" which states several possibilities to define a "function".
But I am lost if I have to decide which to use in an special example:

If I type

sage: f = function('f')
sage: type(f)
<class 'sage.symbolic.function_factory.NewSymbolicFunction'>
sage: var('x')
x
sage: type(f(x))
<type 'sage.symbolic.expression.Expression'>

ok, no surprise.  But

sage: g = function('g', x)
sage: type(g)
<type 'sage.symbolic.expression.Expression'>
sage: type(g(x))
<type 'sage.symbolic.expression.Expression'>
sage: h1 = sin(f(x))
sage: type(h1)
<type 'sage.symbolic.expression.Expression'>
sage: h2 = lambda t: sin(f(t))
sage: type(h2)
<type 'function'>
sage: h1.diff(x)
cos(f(x))*D[0](f)(x)
sage: h2.diff(x)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call
last)

/home/ecki/<ipython console> in <module>()

AttributeError: 'function' object has no attribute 'diff'


What's the difference between f and g?  Why can I differentiate a
symbolic expression, but not a function?  As a mathematician I expected
the other way :-(  The tutorial states that S(x) = sin(x) defines a
"callable symbolic expression".  But I get

sage: S(x) = sin(x)
sage: type(S)
<type 'sage.symbolic.expression.Expression'>
sage: type(S(x))
<type 'sage.symbolic.expression.Expression'>

Is there a difference between a "callable symbolic expression" and a
"symbolic expression"?  Why can I type

sage: S.diff()
x |--> cos(x)

but

sage: sin.diff()
---------------------------------------------------------------------------
AttributeError ...


Is there any more comprehensive description of the different types of
functions and symbolic expressions and when to use them?  Of course, I
can go the hard tour and dig into the source, or I play around until I
get the "right feeling", but I wonder if there is an easier way.

Thanks in advance

     Eckhard

My system:

Dell Optiplex GX620, Intel Pentium 630, 1GB RAM

:~$ uname -a
Linux Adler 2.6.24-27-generic #1 SMP Fri Mar 12 00:52:19 UTC 2010 x86_64
GNU/Linux
:~$ lsb_release -d
Description:    Ubuntu 8.04.4 LTS
up to date 
:~$ sage --version
| Sage Version 4.3.3, Release Date: 2010-02-21                       |
installed tar ball:
sage-4.3.3-linux-64bit-ubuntu_8.04.4_lts-x86_64-Linux.tar.gz

-- 
  Dr. Eckhard Kosin
  Services in Mathematics and Simulation

  mailto:e...@mathematik-service-kosin.de
  http://www.mathematik-service-kosin.de


-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using "remove me" as the subject.

Reply via email to