cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Translate the entire conversation x

Can plot but can't display the first and second derivative from odesolve

GM_13009850
2-Explorer

Can plot but can't display the first and second derivative from odesolve

Hi, Prime 10.0.0.0 problem, when using the odesolve, I can display the displacement vector, but I can't list the first and second derivatives, when using the prime operator.  I can ask for discrete values, but the range variable, only works for the displacement term. I get a message stating that the "calculation is not converging to a solution", although I can plot it. Can anyone assist?, 

GM_13009850_0-1749557655325.png

 

4 REPLIES 4
Werner_E
25-Diamond I
(To:GM_13009850)

The function you get with odesolve is valid only from 0s up to 'duration'.
The numeric algorithm used to calculate derivatives seems to be using left and right neighbour points. But there is no left neighbour for t=0 (meaning that trying to evaluate x(.0.001s)= will fail) and no right neighbour for t=duration.

So chances are that the evaluation of x'(0s)= and/or x'(duration)= will fail. You may test that, I can't as I am limited to the free Express version and can't use a solve block.

When used for plotting, the plot ignores the values which throw an error and happily will plot the rest. But when you evaluate x'(trange),even just one faulty value will turn the whole expression into an error. Thats the reason for the error.

I see two, maybe three workarounds:

 

1)  for the display of the values of x' and x'' use a different range which runs e.g. from 1 µs up to duration-1µs (experiment with the value I have chosen to be 1µs until it works, maybe 1µs is too small)

 

2)  You may define separate functions for the first and second derivative and use something like x1 := try  x'(t)   on error  NaN to catch the error.

 

3) ?? Not sure about this. You may try to solve your ODE symbolically. That way you would get a symbolic function x(t) which is not limited to the range 0 .. duration. See -> Solving ODEs Symbolically

I can't test drive it myself and I am not sure if Prime is capable to solve this ODE with units. In any case you should check/activate the option "Units/Constants in Symbolics" in the calculation options when using symbolics and units.

Werner_E_0-1749567615505.png

 

 

BTW, ranges are NOT vectors and range variables are not made to be used the way you did.

While x(trange)=... works OK and the result may look like a vector, its is not a vector but rather kind of an invalid object. You can tell so as you will see an error if you try to assign it a variable like X:=x(trange).

You rather should use vectors and apply vectorization to do the job.

 

Is there any special reason why you divide x(trange)= by the unit mm? You could do without and simply change/overwrite the unit meter you will see at the result by the desired mm

LucMeekes
23-Emerald IV
(To:GM_13009850)

What happens if you divide x'(trange) by (the unit) mm/s ?

 

Also it may help to know that:

LucMeekes_0-1749569825688.png

(which you should be able to find with symbolically solving the DE).

Then you can plot, without problems:

LucMeekes_0-1749570159081.png

 

(where the division by 4 and 40 are just to scale the values of velocity and acceleration respectively).

 

Success!
Luc

Usually, if we can plot the data it can show the values.
Odesolve numerically evaluate the values for x and dx/dt seems to be able to calculate the value.

However, the dx/dt of start point and end point may causes the error. 

Therefore use try on error to avoide the error.

Then we can get the data. You can edit the unit what you want such as mm/s.

 

image.pngimage.pngEnd point shows the data. But this is error. You can check it by another end time setting.

image.pngimage.png

x'' value at t=0 must check!

image.pngimage.png

Werner_E
25-Diamond I
(To:GM_13009850)

Now I got access to a Prime license and can testdrive your sheet.

As ttokoro already has shown, the evaluation fails at the left end (0 s) of the interval of valid values. So it look like the numeric derivative algorithm only uses the left neighbour for its calculations.

The workarounds I described still apply.

Here is one way. I defined functions for the first and second derivative and trapped the error with try...on error..

Then I used these functions to calculate the values (using vectorization) and assigned it to variables (capital X).

Werner_E_0-1749667287355.png

The function range2vec used to convert a range into a vector is provided in the attached Prime 10 sheet. Starting with Prime 11 you could use the new built-in function "vec" to do the very same task.

You may also use the vectors created for plotting

Werner_E_1-1749667407980.png

I tried if Prime would be able to symbolically solve your ODE and succeeded.

It may have been a better idea to do so before the variables are defined as Luc has shown, but I did it using the already defined constants. Because the symbolics does not know anything about units it can't simplify the result and so it looks quite a mess 😉

Werner_E_2-1749667656661.png

For the function x(t) to be evaluated numerically as we need its mandatory to turn on the option "Units/Constants in Symbolics". It may be necessary to let the sheet recalculate after enabling this option.

Now you can define a vector for time values (the necessary "vec" function is provided in the attached sheet - its built-in starting with P11) and create corresponding vectors for displacement, velocity and acceleration.

Werner_E_3-1749667880320.png

If you like you may also create a table of values

Werner_E_0-1749680273510.png

 

A time range variable should only be used for plotting

Werner_E_5-1749668001242.png

 

Prime 10 sheet attached

 

Announcements


Top Tags