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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to parameterize Odesolve

JohnRudnicki
14-Alexandrite

How to parameterize Odesolve

I am using Odesolve to solve a set of equations. It works fine, but I want to make the solution depend on a parameter. I cant seem to get the syntax right. Or maybe something else is wrong. What am I doing wrong?

1 ACCEPTED SOLUTION

Accepted Solutions

Maybe that way:

You could also use something like this

which looks more versatile but definitely is NOT recommended, at least not when it comes to plotting.

Reason: The whole solve block is called again for every single point which is plotted. You will see the long plotting time when you give it a try. For the calculation of a few discrete values it does not matter, of course.

WE

View solution in original post

7 REPLIES 7

Maybe that way:

You could also use something like this

which looks more versatile but definitely is NOT recommended, at least not when it comes to plotting.

Reason: The whole solve block is called again for every single point which is plotted. You will see the long plotting time when you give it a try. For the calculation of a few discrete values it does not matter, of course.

WE

JohnRudnicki
14-Alexandrite
(To:Werner_E)

Thanks. So what do you recommend (for plotting)? Using the ode solvers, e.g. rkfixed, directly?

Ok. Never mind. I did not read your answer carefully enough. Thanks again.

With rkfixed by help of a local function

5_12_RKfixed_Funct_MC_12.png

I thought I learned how to do this from the previous post, but evidently not.

JohnRudnicki wrote:

I am using Odesolve to solve a set of equations. It works fine, but I want to make the solution depend on a parameter. I cant seem to get the syntax right. Or maybe something else is wrong. What am I doing wrong?

There are 2 or 3 problems:

1) You renamed your function (y -> y1) but forgot to do so twice when you call f inside the solve block

2) Odesolve gives you the function(name) without arguments, so Y(0.02) is boldly spoken just the function name - you have to provide the argument

3) While the above works, its very inefficient because the solve block is now called for every single evaluation. That's OK if you just calculate a few values, but if your plot is evaluated for 1000 values of t, the solve block is called 1000 times an this takes quite a lot of time. So its better to call the solve block just once and store the result to a new variable/function name, which then can be used as a function the normal way:

Give it a try and compare speed 😉

Regards

Werner

JohnRudnicki
14-Alexandrite
(To:Werner_E)

Thanks (again!).

Top Tags