Ask Your Question
0

plotting: value error variable not found

asked 2014-09-26 03:53:20 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi, I'm new to sage and hope that anybody can help me.

I tried to plot two functions X1 and X2 which both depend on several parameters (k, j0, j1, jMax, a0, aMax, a1, v0, v1, vMax, x). I chose a value for every variable except for vMax because I wantet to plot X1 and X2 as a function of vMax. So I typed

plot(X1(k=5, j0=2, j1=4, jMax=10, a0=5, aMax=20, a1=3, v0=10, v1=100, vMax=vMax, x=2000), (vMax, 0, 200))

and it worked just fine. I wanted to do exactely the same with funktion X2, but then I got an value error:

sage: plot(X2(k=5, j0=2, j1=4, jMax=10, a0=5, aMax=20, a1=3, v0=10, v1=100, vMax=vMax, x=2000), (vMax, 0, 200))
Traceback (click to the left of this block for traceback) 
...
ValueError: Variable 'vMax' not found

I don't know, why vMax is not found, as the function is definitely dependent of it. Moreover, with function X1 it just worked as expected!

Yeah, sure, I should add some more details.

I constructed X1 and X2 recursively as they are the way X, which is the integral of the acceleration a, which is the integral of the velocity v and so on. In the end, I get

X1(k, j0, j1, a0, aMax, a1, v0, v1, vMax, x) = -1/24*(j0 -
jMax)^4/k^3 + 1/6*(j0 - jMax)^3*j0/k^3 + 1/24*jMax^4/k^3 - 1/2*a0*(j0 -
jMax)^2/k^2 - 1/2*aMax*jMax^2/k^2 + (j0 - jMax)*v0/k - jMax*vMax*/k + x +
1/48*((2*a0 - 2*aMax + jMax^2/k - (j0^2 - jMax^2)/k)^3*k^2/jMax^2 +
24*(2*a0 - 2*aMax + jMax^2/k - (j0^2 - jMax^2)/k)*k^2*v0/jMax -
3*(2*a0*k^2 - (j0^2 - jMax^2)*k)*(2*a0 - 2*aMax + jMax^2/k - (j0^2 -
jMax^2)/k)^2/jMax^2 + 4*(2*j0^3 - 3*j0^2*jMax + jMax^3 - 6*(a0*j0 -
a0*jMax)*k)*(2*a0 - 2*aMax + jMax^2/k - (j0^2 - jMax^2)/k)/jMax)/k^2 -
1/48*((2*a1 - 2*aMax + jMax^2/k - (j1^2 - jMax^2)/k)^3*k^2/jMax^2 -
24*(2*a1 - 2*aMax + jMax^2/k - (j1^2 - jMax^2)/k)*k^2*vMax/jMax -
3*(jMax^2*k - 2*aMax*k^2)*(2*a1 - 2*aMax + jMax^2/k - (j1^2 -
jMax^2)/k)^2/jMax^2 + 4*(jMax^3 - 6*aMax*jMax*k)*(2*a1 - 2*aMax +
jMax^2/k - (j1^2 - jMax^2)/k)/jMax)/k^2 - 1/24*((j1 + jMax)^4*jMax/k -
4*(j1 + jMax)^3*jMax^2/k + 24*(j1 + jMax)*jMax*k*vMax + 6*(2*a1*jMax*k^2
- (j1^2*jMax - jMax^3)*k)*(j1 + jMax)^2/k^2 - (3*j1^4 - 6*j1^2*jMax^2 ...
(more)
edit retag flag offensive close merge delete

Comments

1

You shoud provide more details on what you typed, in particular on how you constructed X1, X2.

tmonteil gravatar imagetmonteil ( 2014-09-26 04:24:48 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-09-29 04:49:27 -0500

tmonteil gravatar image

updated 2014-09-29 05:52:23 -0500

The symbolic variable jMax is not defined. You can either define it separately:

sage: var('jMax')

sage: X2(k, j0, j1, a0, aMax, a1, v0, v1, vMax, x) = -1/24*jMax^4/k^3 +1/2*aMax*jMax^2/k^2 + jMax*vMax/k + 1/48*((2*a1 - 2*aMax + jMax^2/k -(j1^2 - jMax^2)/k)^3*k^2/jMax^2 - 24*(2*a1 - 2*aMax + jMax^2/k - (j1^2 -jMax^2)/k)*k^2*vMax/jMax - 3*(jMax^2*k - 2*aMax*k^2)*(2*a1 - 2*aMax +jMax^2/k - (j1^2 - jMax^2)/k)^2/jMax^2 + 4*(jMax^3 -6*aMax*jMax*k)*(2*a1 - 2*aMax + jMax^2/k - (j1^2 - jMax^2)/k)/jMax)/k^2+ 1/24*((j1 + jMax)^4*jMax/k - 4*(j1 + jMax)^3*jMax^2/k + 24*(j1 +jMax)*jMax*k*vMax + 6*(2*a1*jMax*k^2 - (j1^2*jMax - jMax^3)*k)*(j1 +jMax)^2/k^2 - (3*j1^4 - 6*j1^2*jMax^2 + 4*jMax^4 + 12*(a1^2 -aMax^2)*k^2 - 12*(a1*j1^2 - (a1 - aMax)*jMax^2)*k)*(j1 +jMax)/k)/(jMax*k^2)

sage: X2
(k, j0, j1, a0, aMax, a1, v0, v1, vMax, x) |--> -1/24*jMax^4/k^3 + 1/2*aMax*jMax^2/k^2 + jMax*vMax/k + 1/48*((2*a1 - 2*aMax + jMax^2/k - (j1^2 - jMax^2)/k)^3*k^2/jMax^2 - 24*(2*a1 - 2*aMax + jMax^2/k - (j1^2 - jMax^2)/k)*k^2*vMax/jMax - 3*(jMax^2*k - 2*aMax*k^2)*(2*a1 - 2*aMax + jMax^2/k - (j1^2 - jMax^2)/k)^2/jMax^2 + 4*(jMax^3 - 6*aMax*jMax*k)*(2*a1 - 2*aMax + jMax^2/k - (j1^2 - jMax^2)/k)/jMax)/k^2 + 1/24*((j1 + jMax)^4*jMax/k - 4*(j1 + jMax)^3*jMax^2/k + 24*(j1 + jMax)*jMax*k*vMax + 6*(2*a1*jMax*k^2 - (j1^2*jMax - jMax^3)*k)*(j1 + jMax)^2/k^2 - (3*j1^4 - 6*j1^2*jMax^2 + 4*jMax^4 + 12*(a1^2 - aMax^2)*k^2 - 12*(a1*j1^2 - (a1 - aMax)*jMax^2)*k)*(j1 + jMax)/k)/(jMax*k^2)

Or add it as an internal variable of your function X2 (it will be automatically injected in the namespace):

sage: X2(k, j0, j1, jMax, a0, aMax, a1, v0, v1, vMax, x) = -1/24*jMax^4/k^3 +1/2*aMax*jMax^2/k^2 + jMax*vMax/k + 1/48*((2*a1 - 2*aMax + jMax^2/k -(j1^2 - jMax^2)/k)^3*k^2/jMax^2 - 24*(2*a1 - 2*aMax + jMax^2/k - (j1^2 -jMax^2)/k)*k^2*vMax/jMax - 3*(jMax^2*k - 2*aMax*k^2)*(2*a1 - 2*aMax +jMax^2/k - (j1^2 - jMax^2)/k)^2/jMax^2 + 4*(jMax^3 -6*aMax*jMax*k)*(2*a1 - 2*aMax + jMax^2/k - (j1^2 - jMax^2)/k ...
(more)
edit flag offensive delete link more

Comments

Okay, thanks! I thought I had defined jMax, but apperently not. Now it works! :)

caesar gravatar imagecaesar ( 2014-09-29 07:42:03 -0500 )edit

I have exactely the same problem! Even if in my worksheet the variable x is defined before (like sage: x = var('x') ), the command to plot my function turns into that ValueError... :(

nemo gravatar imagenemo ( 2014-09-30 02:54:35 -0500 )edit
0

answered 2016-08-20 13:58:28 -0500

leo krupski gravatar image

updated 2016-08-20 14:01:06 -0500

This error can occur when you use simultaneous assignments. This returns error.

@interact
def _(a=-3, b=3,c=(-10,10),f=y^2*sin(y^c)):
     show(plot(f,(x,a,b)))

This does not:

@interact
def _(a=-3, b=3,c=(-10,10),f=y^2*sin(y^c)):
     f=y^2*sin(y^c))
     show(plot(f,(x,a,b)))
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-09-26 03:53:20 -0500

Seen: 558 times

Last updated: Aug 20 '16