[MATLAB] I am getting this error, could anyone solve it please?

  • Context: MATLAB 
  • Thread starter Thread starter Avan
  • Start date Start date
  • Tags Tags
    Error Matlab
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting an error encountered while using MATLAB's ODE solver for a logistic model with an oscillatory term. Participants explore potential causes of the error, suggest modifications to the code, and discuss the mathematical implications of the problem.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports an error from the ODE solver indicating it cannot meet integration tolerances without reducing the step size below a minimum value.
  • Another participant suggests adjusting the absolute and relative tolerance settings to allow for less accuracy, which could help the solver continue.
  • Some participants propose reducing the size of the time array to alleviate the solver's issues, suggesting a smaller range or larger increments.
  • There are discussions about the mathematical nature of the problem, including the potential for singularities in the solution and the behavior of the function at certain time points.
  • One participant expresses uncertainty about how to analyze the behavior of the function as both time and population change, seeking clarification on how to proceed with the investigation.
  • Another participant mentions that the differential equation can be solved analytically and points out the existence of singularities, suggesting that these may be related to the issues faced in MATLAB.
  • There is a query about using the Bernoulli method for the analytical solution and how to continue running the code despite singularities.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to resolve the error. Multiple competing views on how to modify the code and analyze the mathematical problem are presented, indicating an ongoing debate.

Contextual Notes

Participants note the potential for singularities in the solution and the implications this has for numerical integration. There are also references to the need for further investigation into the behavior of the function at specific time points.

Who May Find This Useful

This discussion may be useful for individuals working with MATLAB for numerical solutions of differential equations, particularly those encountering similar integration issues or interested in the mathematical properties of logistic models with oscillatory terms.

Avan
Messages
25
Reaction score
0
[MATLAB]
The cod is:

function RunLogOscilNumeric3
k =10;
p0 =0.001;
t = [0:0.01:10000 ];
omega = 1;
N0 = 1;

options =[ 'AbsTol',1e-3,'RelTol',1e-6]
% options =odeset( 'RelTol',1e-6 ,'stats','on');

[t,p]=ode45(@logOscilnumeric3,t,p0,options,omega,k,N0);

Pmax = max(p)
Pmean = mean(p)
figure(1)
plot(t,p)

1;

% function dpdt = logOscilnumeric3(t,p,omega,k,N0)
% dpdt = N0.*p - (N0.*sin(omega.*t).*p.^2/k);
% end

The error is :
Warning: Failure at t=1.058553e+01. Unable to meet integration tolerances
without reducing the step size below the smallest value allowed
(2.842171e-14) at time t.
> In ode113 at 425
In RunLogOscilNumeric3 at 11
 
Physics news on Phys.org
Your ode solver can't continue within it's limits. You could either change your options (AbsTol and RelTol) such that less accuracy is needed to continue.
This will result in a slightly less solution but bigger interval where you know the solution.

Do you know how a differential equation is solved numerically?
If not I strongly recommend you at least study the basics. If you do that errors as the one you get should be clear to you.

Also, use code-tags please (as noted and illustrated in your previous thread)

NOTE: I couldn't be bothered checking the documentation whether AbsTol and RelTol really mean what I said.
That's something you should do AND include in the thread.
 
JorisL said:
Your ode solver can't continue within it's limits. You could either change your options (AbsTol and RelTol) such that less accuracy is needed to continue.
This will result in a slightly less solution but bigger interval where you know the solution.

Do you know how a differential equation is solved numerically?
If not I strongly recommend you at least study the basics. If you do that errors as the one you get should be clear to you.

Also, use code-tags please (as noted and illustrated in your previous thread)

NOTE: I couldn't be bothered checking the documentation whether AbsTol and RelTol really mean what I said.
That's something you should do AND include in the thread.

Thank you.

I know about the numerical solution and even I tried to change a tolerances and the ode solver and changing my parameters' values but I still get the warning message!

I put my question here because sometimes it is useful to get experience from other people.

I tried to do the code-tags but it is still the same when I am posting it.

Regards
 
Can you describe the mathematical problem you are trying to solve?

I don't really know how to use Matlab for this. So I hope I can shed some light on this from a general point of view.

About the code tags, just add [code*] before the code and [/code*] after the code.
Remember to remove the * from the tags.
 
What I am trying to do is :: I have the Logistic system ,, I am trying to add an oscillatory term to it and changing the angular frequency and the growth rate just to see the effect of this on my system. The above code is to solve the system numerically and use the results for more calculations.

Please,, could you help me to contact with someone has an experience with MATLAB?

Best regards
 
Avan said:
I know about the numerical solution and even I tried to change a tolerances and the ode solver and changing my parameters' values but I still get the warning message!
Try changing your array of time values. In your code you have this:

Code:
t = [0:0.01:10000 ];
There are 1,000,000 elements in that array! Reducing that size of that array might have an effect on the warning you're getting. I would change the above to this:
Code:
t = [0:0.01:100 ];
This change would reduce the array size from 1,000,000 elements to 10,000 elements.

If you absolutely have to have an ending time of 10,000, increase the size of your increment to, say, 0.1 or even 1.0.
 
  • Like
Likes   Reactions: JorisL
Mark44 said:
Try changing your array of time values. In your code you have this:

Code:
t = [0:0.01:10000 ];
There are 1,000,000 elements in that array! Reducing that size of that array might have an effect on the warning you're getting. I would change the above to this:
Code:
t = [0:0.01:100 ];
This change would reduce the array size from 1,000,000 elements to 10,000 elements.

If you absolutely have to have an ending time of 10,000, increase the size of your increment to, say, 0.1 or even 1.0.

Many thanks but Unfortunately, Your suggestion does not work and I previously tried it.
If I integrate for t = [0 : 0.01 : 10] I don't have any problem but the problem begins at t=1.057848e+01 ,, and as you know taking the time until 10 is very limited so I need to plot my system to study it's behaviour for longer time.

Any other suggestions please?
 
You need to find out what happens at that time.

Can you plot the result upto 1.05e+01 ?
This might give an indication.
 
JorisL said:
You need to find out what happens at that time.

Can you plot the result upto 1.05e+01 ?
This might give an indication.
 

Attachments

  • #10
Obviously the solution diverges, a lot.

You should check what the sign of the right-hand side is as t and p change.
That is, investigate your function like shown here: http://www.bymath.com/studyguide/ana/sec/ana7.htm

If the function remains positive you are done. If it becomes negative you might just have a local singularity.
 
  • #11
JorisL said:
Obviously the solution diverges, a lot.

You should check what the sign of the right-hand side is as t and p change.
That is, investigate your function like shown here: http://www.bymath.com/studyguide/ana/sec/ana7.htm

If the function remains positive you are done. If it becomes negative you might just have a local singularity.

Sorry, Because I have two variables ,, Could you Explain to me more or help me to do that please? You said as t and p change so should I check at both change together or change one and fixing the other.
 
  • #12
I'd say make a 3D plot.
Let t and p be positive.

Why p positive? Because you need a negative value in the "future" while all you have now is a positive p.
You need to check if there exists a t where a positve p results in a negative derivative.
 
  • #13
Your differential equation can be solved analytically. It has many singularities, i.e., points where p→∞. The first one is at t ≈ 10.5785, which is close to where MATLAB has problems.
 
  • #14
DrClaude said:
Your differential equation can be solved analytically. It has many singularities, i.e., points where p→∞. The first one is at t ≈ 10.5785, which is close to where MATLAB has problems.

Many thanks for your replay.
About the analytical solution,Could I use the Bernoulli method to solve it?
Secondly, If I want to deal with this system even if there is a singularity in some points, How could I continue running my code please?

Regards
 

Similar threads

  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
5K
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
7K