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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Maximize and root issues with ODESOLVE solution

SL_8777172
3-Visitor

Maximize and root issues with ODESOLVE solution

Hi,

I'm having problems with using MathCAD to extract the time at which the maximum value of a function happens. I've attached a file with the example.

 

In the attached file, after some initial setup of parameters etc on page 1, on page two I define 2 ODEs in a solve block and solve them with ODESOLVE. This seems to work, and I have plotted the outputs in several graphs. They look as I expect. At some time I get a single peak produced on the graph of f(t). I want Mathcad to tell me at what t this peak happens.

 

I've tried using Maximize, and this gives me incorrect answers for t.

 

I've then tried differentiating f(t) and attempting to find the root that corresponds to the peak of f(t). This works for some sets of parameters and I thought I'd cracked it. But then I change one of the parameters slightly and root stops working, giving me the error message "The ODE solution is calculated over a limited range. Choose a value within this range or expand the range".

 

Any suggestions?

 

Thanks,

Steve

 

 

 

4 REPLIES 4
LucMeekes
23-Emerald III
(To:SL_8777172)

Change the second argument to you odesolve() call to a higher value, e.g. from 310*10^-6 to 400*10^-6, to find the root for tpulse=50*10^-6.

 

Incidentally,

You've defined mJ at the top, but it's not a unit. You need to change the label of mJ to 'Unit' to use it as a unit. But I see that you don't use units at all. Consider using units, and note that h and c are predefined constants in Prime.

 

Success!
Luc

HI! Thanks very much for looking at this.

 

Good point on defining mJ as a unit. I do use units in my bigger sheet of this, but I stripped a whole load of irrelevant stuff out before posting my issue here. And when I first used MathCAD a long long time ago I don't think it did know what h and c were. So I'm in the habit of putting them up there but should probably stop!

 

So, changing that argument to a higher value works for some values of tpump (including the 50microsecond example), but not others. By increasing the argument I was able to set tpump as high as 80microseconds and have Root work. But at 81 microseconds and higher it stops working again with the same error and doesn't seem to work no matter what I set the argument to.

 

I need a more robust solution than this that can be used for a wide range of values of tpump, and also changing some other parameters too. It would be nice to understand why it is having problems with this calculation so that I can understand how to create a more reliable solution.

 

Thanks again,

Steve 

The on first sight wrong error message you get with your derivative approach and t.pump=50*10^-6 can be avoided if you set the system variable TOL to a lower value

Werner_E_0-1698031205391.png

actually Prime is happy already with 10^-7.

Werner_E_1-1698031437886.png

But there is no guarantee that this approach would cure the problem for all possible values you would like to change. So I won't call it a reliable and robust solution.

 

 

Hi Werner.

Thanks very much for taking a look at the problem. Adjusting the TOL does allow me to increase tpump a bit further. But as you suggested might be the case, it doesn't help for all values. The same error messages occur for higher values of tpump.

 

I'm still looking for ways to improve the reliability of the method. Or if anyone could suggest an alternative method then that would be great too!

 

Thanks,
Steve

Top Tags