Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Dec 8, 2014 #1
    [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
     
  2. jcsd
  3. Dec 8, 2014 #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.
     
  4. Dec 9, 2014 #3
    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
     
  5. Dec 9, 2014 #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.
     
  6. Dec 9, 2014 #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
     
  7. Dec 9, 2014 #6

    Mark44

    Staff: Mentor

    Try changing your array of time values. In your code you have this:

    Code (Text):
    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 (Text):
    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.
     
  8. Dec 10, 2014 #7
    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?
     
  9. Dec 10, 2014 #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.
     
  10. Dec 10, 2014 #9
     

    Attached Files:

    • 123.docx
      123.docx
      File size:
      16.2 KB
      Views:
      101
  11. Dec 10, 2014 #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.
     
  12. Dec 10, 2014 #11
    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.
     
  13. Dec 10, 2014 #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.
     
  14. Dec 10, 2014 #13

    DrClaude

    User Avatar

    Staff: Mentor

    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.
     
  15. Dec 10, 2014 #14
    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: [MATLAB] I am getting this error, could anyone solve it please?
Loading...