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

• MATLAB
• Avan

#### Avan

[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

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.

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.

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.

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

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.

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

You need to find out what happens at that time.

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

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

• 123.docx
16.2 KB · Views: 288
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.

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.

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.

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.

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.