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

In summary, the cod is:function RunLogOscilNumeric3k = 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(
  • #1
Avan
25
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
  • #2
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.
 
  • #3
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
 
  • #4
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.
 
  • #5
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
 
  • #6
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 JorisL
  • #7
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?
 
  • #8
You need to find out what happens at that time.

Can you plot the result upto 1.05e+01 ?
This might give an indication.
 
  • #9
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

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

1. Why am I getting an error in MATLAB?

There are many possible reasons for getting an error in MATLAB, such as incorrect syntax, undefined variables, or issues with the code itself. It is important to carefully read the error message and check your code for any mistakes, as well as referencing documentation or seeking help from online forums or colleagues.

2. How can I fix an error in MATLAB?

The solution to fixing an error in MATLAB will depend on the specific error message and the code that you have written. Common strategies for fixing errors include debugging and troubleshooting by checking for syntax errors, ensuring that variables are defined and initialized correctly, and verifying that your code follows the correct logic.

3. Can anyone help me solve this error in MATLAB?

It is always a good idea to seek help from others when you encounter an error in MATLAB. You can ask for assistance from colleagues, classmates, or online communities such as MATLAB forums. When asking for help, be sure to provide as much information as possible about the error, your code, and any steps you have already taken to try and solve the issue.

4. How can I prevent errors from occurring in MATLAB?

While it is impossible to completely eliminate errors in any programming language, there are steps you can take to minimize the likelihood of encountering errors in MATLAB. These include writing clear and organized code, testing your code as you go, and referencing documentation or seeking help when needed.

5. What resources can I use to learn more about fixing errors in MATLAB?

There are many resources available to help you learn more about fixing errors in MATLAB. These include the official MATLAB documentation, online tutorials and courses, and forums where you can ask for help from experienced users. You can also practice by working on coding projects and learning from your mistakes.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
29
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
826
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
Back
Top