Hello Sepidar,
in your second example you create functions without a return
statement. Per default Python returns None if the function ends
without an explicit return statement. That is the cause for the
error.
Just define the functions like this:
def n(t):
return cos(a*t),sin(a*t),0
def p(t):
return d*n(t)[0],d*n(t)[1],d*n(t)[2]
Harald's example worked without return statement, because he defined f
as a symbolic expression (no def keyword).
With best regards,
Lars
On Jun 19, 9:25 pm, Sepidar <[email protected]> wrote:
> Now consider this case:
>
> var('x y z t a d')
> def n(t):
> cos(a*t),sin(a*t),0
> def p(t):
> d*n(t)[0],d*n(t)[1],d*n(t)[2]
>
> When I try p(0) I get error. Why?
>
> On Jun 19, 10:17 pm, Harald Schilly <[email protected]> wrote:
>
>
>
> > Functions can have several arguments. For g, you can define a python
> > function that returns multiple arguments - this is then a tuple that you can
> > unwrap with "*". Look carefully at the following session:
>
> > sage: var('a b c x y z')
> > (a, b, c, x, y, z)
>
> > sage: f(x,y,z) = a*x^2+b*x+c
>
> > sage: f(1,2,3)
> > a + b + c
>
> > sage: f(2,3,4)
> > 4*a + 2*b + c
>
> > sage: def g(x,y,z):
> > ....: return x^2, y^2, z^2
> > ....:
>
> > sage: f(*g(tan(x), sin(x), cos(x)))
> > a*tan(x)^4 + b*tan(x)^2 + c
>
> > sage: f(*g(tan(x), sin(2*x), 2*cos(x)))
> > a*tan(x)^4 + b*tan(x)^2 + c
>
> > H
>
> > PS: your definition of f might be wrong, because there is a y and z but it
> > is not used on the right-hand side!
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org