I looked all over and I just can't figure it out.

var('a');
var('x y z');
x = cos(a)^3;
y = sin(a)^3;
z = cos(2*a);

pl1=parametric_plot3d( (cos(t)^3, sin(t)^3, cos(2*t)), (t, 0, 2*pi));

a = pi/4;
pl2=parametric_plot3d( (x + t*(derivative(x)), y + t * (derivative(y)), z + t * (derivative(z))), (t,0,1), texture="red");

edit retag close merge delete

Sort by » oldest newest most voted

This happens because of the way python handles variables, assignment, and references. Try the following:

sage: var("x,a")
(x, a)
sage: x = cos(a)
sage: a = 1/4
sage: print x
cos(a)
sage: print(a)
1/4


In this code, a at first refers to a symbolic variable, then the name a is reassigned to the number 1/4. When x gets printed you still see the symbolic variable there whose name is a.

To get a value for a substituted into x, y, z try using the .subs method:

sage: var('a')
a
sage: x = cos(a)
sage: x.subs(a=1/4)
cos(1/4)

more

you forgot to do

var('t')


You also need to re-so assignments of x, y, and z after you set a to a particular value. I.e.

a = pi/4;
x = cos(a)^3;
y = sin(a)^3;
z = cos(2*a);
pl2=parametric_plot3d( (x + t*(derivative(x)), y + t * (derivative(y)), z + t * (derivative(z))), (t,0,1), texture="red");


works just fine.

more