Skip to main content
1-Visitor
March 24, 2013
Solved

min/max of odesolve solution

  • March 24, 2013
  • 5 replies
  • 2905 views

Hi

I tried to find the max value of a solution from odesolve.

As argument I used a vector. It works fine for the direct solution of odesolve. But if I try to use a function on the solution (derivate with respect to time) I get stucked.

You have to scroll down a little bit and you will find the explained problem.

Thanks in advance for helping me out.

Best answer by Werner_E

1) in "max(derv(vh,i))" there is missing the closing parenthesis

2) your function "derv" uses indices i-1 and i+1. Therefore you can only apply indices from 1 to pkt-1 and not, as you do, from 0 to pkt. Thats the reason for the error regarding the array index you get everytime you call derv(). The two invalid indices being 0-1 and pkt+1.

3) Even if you correct the above you would be disappointed. You feed a range variable in derv(...) and so max(..) aould be applied to every element singly so you would get pkt times the max of a single constant.

You have to create a vector to get max to work

odemax1.png

Edited: Changed file, added another method to get the derivative to get the maximum with better accuracy.

5 replies

Werner_E
Werner_E25-Diamond IAnswer
25-Diamond I
March 24, 2013

1) in "max(derv(vh,i))" there is missing the closing parenthesis

2) your function "derv" uses indices i-1 and i+1. Therefore you can only apply indices from 1 to pkt-1 and not, as you do, from 0 to pkt. Thats the reason for the error regarding the array index you get everytime you call derv(). The two invalid indices being 0-1 and pkt+1.

3) Even if you correct the above you would be disappointed. You feed a range variable in derv(...) and so max(..) aould be applied to every element singly so you would get pkt times the max of a single constant.

You have to create a vector to get max to work

odemax1.png

Edited: Changed file, added another method to get the derivative to get the maximum with better accuracy.

1-Visitor
March 25, 2013

Thanks a lot. I got it right now. Perfect explanations!


As I changed some things I got other troubles.
For example with the mathcad derivative. If I don't use the bold self-written formula, it does not calculate to the end. I marked the questions green. Feel free to comment.

Werner_E
25-Diamond I
March 25, 2013

Its important to keep range variables and vectors apart!

See if the attached helps.