Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
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?
Solved! Go to Solution.
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
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
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
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
Thanks (again!).