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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

ODE solve with Stiffr and Parameter

fgörlich
8-Gravel

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?

 

grafik.png

 

I hope someone can help. Thanks

 

 

16 REPLIES 16

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

test.PNG

 


@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.

And how do you do that? I had try different solution but only that works.

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?

 

Please attach your Mathcad Prime worksheet in archive to the message.

Here is the file,

 

can I write it without the programming part?

 

best Regards,

Fabian


@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.

Bild.PNG

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


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.

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.

Unbenannt.PNG

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? 

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

Bild.PNG

Hey,

 

I think it is the same like you. What is wrong?

 

12w3213.PNG

 

Thanks for help!


@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.

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?

 

Stiffr.PNG



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.

 

Just a quick look, you've got a loop index (i) that doesn't address anything. 

Capture.PNG

Announcements