[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
SUMMARY

The discussion centers on a MATLAB error encountered during the numerical solution of a differential equation using the ode45 solver. The user receives a warning indicating that the integration tolerances cannot be met without reducing the step size below the minimum allowed value. Key suggestions include adjusting the time array size and investigating the behavior of the function at critical points, particularly around t ≈ 10.5785, where singularities may occur. The conversation emphasizes the importance of understanding numerical methods and the implications of changing tolerance settings in MATLAB.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of numerical methods for solving differential equations
  • Knowledge of MATLAB's ode45 solver and its options (AbsTol, RelTol)
  • Basic concepts of singularities in mathematical functions
NEXT STEPS
  • Research the use of MATLAB's ode45 solver and its configuration options
  • Study the implications of numerical integration tolerances in MATLAB
  • Learn about singularities in differential equations and their impact on solutions
  • Explore analytical methods for solving differential equations, such as the Bernoulli method
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those working with numerical solutions of differential equations, researchers in mathematical modeling, and anyone encountering integration issues in MATLAB.

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