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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

This variable is undefined for derivative

SS_9781956
7-Bedrock

This variable is undefined for derivative

I am unable to get the evaluation of Derivative in attached worksheet.  How do I get it evaluated? 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Werner_E)

As Terry kindly provided a working sheet by adding an appropriate value for rho, here some additional remarks:

The calculation of the derivatives fails because of the end values (0s, 20s) as already explained

Werner_E_0-1692739081551.png

You may fix this by using try & catch

Werner_E_2-1692739250578.png

 

It may be worth to define a small utility function to do that job

Werner_E_3-1692739280860.png

 

!! !BUT ,,,

You can't assign these values to a variable for later use as its NOT a vector! So of course vectorization does not help at all

Werner_E_4-1692739374095.png

 

Despite of the misleading error message the true reason is (as written in my previous answer) that t is a range, not a vector!.

There is an undocumented trick to turn a range into a vector by following the assignment with an inline evaluation:

Werner_E_5-1692739481284.png

t_vec is now a legitimate vector, not a range (unfortunately ranges and vectors look the very same in Prime).

A more "legal" way to create that very same vector is seen here:

Werner_E_6-1692739571219.png

Now you can use this vector to create a table for later use - don't forget about vectorization (the arrow over the expression)

Werner_E_7-1692739654879.png

or create a more comprehensive table

Werner_E_8-1692739697880.png

But of course you still can't evaluate the functions and their derivatives symbolically as you tried to do because the functions derived by OdeSolve are numeric only.

 

 

 

View solution in original post

3 REPLIES 3

Hi,

Need to define a value for Rho typically density so I chose air at 1.25kg/m^3.

Capture.JPG

Cheers

Terry

Werner_E
25-Diamond I
(To:SS_9781956)

Your sheet does not work - maybe due to an error in the protected area. First error message is that rho is not defined.

But the problem is clear anyway: A solve block with odesolve returns a numerical solution, not a symbolic one. You don't get a symbolic function definition and so you can't demand a symbolic derivative.

All you can do is to numerically evaluate the functions at positions within the interval from 0 to 20 s and you may also numerically evaluate their derivatives as you already did in the plot. So Phi(2s)= will work, but Phi(t)= or Phi(t)-> can't - apart from the fact that you already defined t as a range!

Starting with version 9 PTC implemented a way to symbolically solve some simple ODEs and systems of ODEs See Solving ODEs Symbolically

If you are in need for a symbolic solution you may give that a try.

 

EDIT: In case that your intention was to just make some sort of table of values, you should not use a range but rather a vector of t-values and call the function vectorized.

The derivatives may fail at the end postions (0s and 20s) because the numeric algorithm needs neigbour-points which do not exist at the ends of the interval. Nonetheless you may filter the failing values and still see the other values or you define a vector of t-values which does not include the problematic end values.
For more help and showing what I mean we would need a working sheet of course.

Werner_E
25-Diamond I
(To:Werner_E)

As Terry kindly provided a working sheet by adding an appropriate value for rho, here some additional remarks:

The calculation of the derivatives fails because of the end values (0s, 20s) as already explained

Werner_E_0-1692739081551.png

You may fix this by using try & catch

Werner_E_2-1692739250578.png

 

It may be worth to define a small utility function to do that job

Werner_E_3-1692739280860.png

 

!! !BUT ,,,

You can't assign these values to a variable for later use as its NOT a vector! So of course vectorization does not help at all

Werner_E_4-1692739374095.png

 

Despite of the misleading error message the true reason is (as written in my previous answer) that t is a range, not a vector!.

There is an undocumented trick to turn a range into a vector by following the assignment with an inline evaluation:

Werner_E_5-1692739481284.png

t_vec is now a legitimate vector, not a range (unfortunately ranges and vectors look the very same in Prime).

A more "legal" way to create that very same vector is seen here:

Werner_E_6-1692739571219.png

Now you can use this vector to create a table for later use - don't forget about vectorization (the arrow over the expression)

Werner_E_7-1692739654879.png

or create a more comprehensive table

Werner_E_8-1692739697880.png

But of course you still can't evaluate the functions and their derivatives symbolically as you tried to do because the functions derived by OdeSolve are numeric only.

 

 

 

Announcements

Top Tags