ODE solve with Stiffr and Parameter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
ODE solve with Stiffr and Parameter
Hi,
I have a question about Mathcad. I want to solve an ODE-system with Parameters. I want to use of Stiffr or Stiffb as a ODE-Solver. I have a minimal example in the file. See also the screenshot. What can i do, to find the error in the code?
I hope someone can help. Thanks
- Labels:
-
Calculus_Derivatives
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
I found a solution. The post helps me a lot:
https://community.ptc.com/t5/PTC-Mathcad-Questions/Solving-of-ODE-with-variable-parameter/td-p/43366
The problem was the Jacob matrix. Is there a solution without programming? Is this possible?
Now my solution looks like that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@fgörlich wrote:
Hi,
I found a solution. The post helps me a lot:
https://community.ptc.com/t5/PTC-Mathcad-Questions/Solving-of-ODE-with-variable-parameter/td-p/43366
The problem was the Jacob matrix. Is there a solution without programming? Is this possible?
Now my solution looks like that
It looks to me that you don't use any programming structures anyway. So what you do inside your "program" "lsg" you could as well do directly on worksheet level.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
And how do you do that? I had try different solution but only that works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
As you don't attach your worksheet we have nothing to play around with.
Whats the problem with writing the four vital assignments you have in your program "lsg" directly in the worksheet using the normal assignment := ?
We see an error in the pic in your first post, but we don't see which error - what the error message is. Its hard to debug a picture. We hardly see if you are using literal or matrix indices, etc.
What about your function A(t,d)? Its not dependent on t as it looks. Is this on purpose?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Please attach your Mathcad Prime worksheet in archive to the message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here is the file,
can I write it without the programming part?
best Regards,
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@fgörlich wrote:
Here is the file,
can I write it without the programming part?
Yes, but are you sure about the correctness of the result. The values in the last column quickly exceed Primes numeric limit (around 10^307) and so just get NaN's .
Without the symbolic evaluation we get an unknown error and I have no clue what the sybolic eval does and why its presence is necessary to get a numeric result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks,
very cool. The System is only a minimal example. It hast no physical meaning.
Other questions. What is, whenn A(t,Y) is a prgrammed function. Here a iteration will start. Than I Can't build a jacobian, because there is no symbolic calculation of D(t,Y) possible. Is there a way two build a numerically jacobian?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Other questions. What is, whenn A(t,Y) is a prgrammed function. Here a iteration will start. Than I Can't build a jacobian, because there is no symbolic calculation of D(t,Y) possible. Is there a way two build a numerically jacobian?
In fact I don't know, I never tried. Guess it should be possible as "stiffr" uses the argument function AJ just numerically and does not need a symbolic representation (at least that's my understanding).
I was still wondering as of the need for the symbolic evaluation in the above example and tried the very same example in Mathcad 15 (I still would trust MC15 more than Prime). The example failed with and without symbolic evaluation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
It is very strange!
I tried different ways to find some solution, but no solution is possible. I tried different combinations of symbolic calculation, but no effect.
This time I make a fuction of stiffr depended of d. There is no solution possible. Also it is not important, when A(t,y,d) ist in program code or normal function.
Is there a chance to predict an own Jacobian?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
D and AJ must be function with two arguments only!
Guess we are back at programming if you'd like to turn the solution in a function of d
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hey,
I think it is the same like you. What is wrong?
Thanks for help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@fgörlich wrote:
Hey,
I think it is the same like you. What is wrong?
I have not the slightest idea 😞
I ran into the same error when I tried to edit your last sheet (test3) accordingly.
It was only after I opened your older test2 sheet and modified it that I got it to work.
Something is very unstable here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I think there is a bug. Without d the jacobian is every time zero in each element. Thats noch possible. In my new file i wrote the file new, and than there wasn't the bug, but also no solution.
Now i have try a new solution method to predict stiffr with function parameter d. I predict Stiffr in a loop and I only predict one time step per loop iteration. with this solution i predict a numerically jacobian. In the next loop I update the time, the initals and so on. It works!
Is that right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Is that right?
At first sight it looks correct.
Its a pity that we have to resort to that kind of solution.
I also think that its a bug in Prime - its bizarre that we have to use a symbolic evaluation to get a result (sometimes). As I had already written Mathcad(15) totally refuses to return a result - neither with nor without symbolic eval. Its refuses to calculate the Jacobian at all.
Guess the function A is just a dummy for demonstration which is the reason for the pointless loop which could be replaced by a much simpler assignment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Just a quick look, you've got a loop index (i) that doesn't address anything.
