I got such an error while running this code.

1 view (last 30 days)
Rajan Bhandari
Rajan Bhandari on 2 May 2018
Edited: Jan on 2 May 2018
function dx=Untitled3(t,x)
I run the code as
and got the error message
Warning: Failure at t=6.905309e-01. Unable to meet integration tolerances without reducing the step size below the smallest value allowed
(1.776357e-15) at time t.
> In ode45 (line 308)
  1 Comment
John D'Errico
John D'Errico on 2 May 2018
Edited: John D'Errico on 2 May 2018
1. Learn to format your code so it is readable. On this site, that means if you paste in code, you need to then select the block of code, then click on the "{} Code" button to format it.
2. I predict that with the use of names like "untitled3", you will one day become known far and wide for producing unreadable spaghetti code.
3. Oh. If you want an answer to your real question, even though I cannot read your code at all, that error from ODE45 almost always means you have a stiff system of equations. So you need to use a solver that can handle stiff problems. That would be tools like ODE15S.

Sign in to comment.

Answers (2)

Torsten on 2 May 2018
instead of
Best wishes
  1 Comment
Jan on 2 May 2018
Very nice! +1
%y'(t) = -x(t) + (1 - 0.2 * y(t)^2) * (x(t) + y(t) * cot(t)) / (y(t)^2 - 1)
dx(2) = -x(1) + (1 - 0.2 * x(2)) * (x(1) + x(2) * cotd(x(3))) / (x(2)^2 - 1);
@Rajan Bhandari: Use spaces to write readable code.

Sign in to comment.

Jan on 2 May 2018
Edited: Jan on 2 May 2018
Beside the stiffness of the system, it can be a pole in the trajectory also. Try it by stopping the integration shortly before the integration fails:
[T, Y] = ode45(@Untitled3, [0, 6.9e-1], [3.228,1.4667,19.72]);
plot(T, Y)
You will see that the first component Y(:, 1) explodes. You cannot integrate over such a pole. This might be a property of the physical system you simulate, or a typo in the formula. [EDITED] See Torsten's answer for such a typo...


Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by