Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.776357e-15) at time t

7 views (last 30 days)
My script consists of 4 ode eq's. Iam solving those using ode45 function.
syms theta
A = cos(theta).*[1 5 6 1 7; 5 0 2 9 3; 1 4 5 1 0; 0 0 0 1 0; 0 0 0 0 1];
B = tan(2*theta).*[8 5 1 7 5; 0 3 1 1 6; 3 1 2 4 7; 0 0 0 0 0; 0 0 0 0 0];
C = sin(2*theta).*[8 5 1; 0 1 6; 2 4 7];
myfun = @(t,y)scriptname(t,y,A,B,C);
% dummy values for tspan and y0
tspan = [0 1];
y0 = zeros(1, 5);
% ode solver
sol = ode45(myfun,tspan,y0);
h = figure;
% plot
for i = 1:3
title(['stator current # ',int2str(i)]);
g = figure;
for i=3
ylabel('Speed, rpm');
title('Mechanical Angular Speed');
function dydt = scriptname(t,y,A,B,C)
inertia = 0.05;
Wr = 2*pi*50;
p =2;
% evaluation of A and B (numerical) with theta = y(3)
Cn = double(subs(C,y(5)));
for i=1:3
Te = 1/2*p*I'*Cn*I
if t<0.75
V = [1.4142*400/sqrt(3)*cos(Wr*t);
% evaluation of A and B (numerical) with theta = y(3)
An = double(subs(A,y(5)));
Bn = double(subs(B,y(5)));
dydt = An\V-(Bn*y);
while running this code, it is giving below error
Warning: Failure at t=7.854990e-01. Unable to meet integration tolerances without reducing the step size below
the smallest value allowed (1.776357e-15) at time t.
And waveforms are coming like this
Can anyone tell me where did i went wrong.
Bathala Teja
Bathala Teja on 14 Sep 2021
it is working fine if i put tspan = [0 0.7];
i know the issue with that if condition.
what i need to change now, i want that condition???

Sign in to comment.

Answers (1)

Saurav on 21 Feb 2024 at 12:14
Hey, Teja,
From the provided information, I understand that you are facing issues in solving an ode equation using the ode45 function.
It is evident from the warning that the simulation is working well until the time mentioned in it. If you change the variable “tspan” value to, for example, [0, 0.7], it is giving the expected plots. Also, I noticed that your parameter “Te” is reaching up to the order of 1E+27. With this scaling, the ODE is impossible to solve numerically as it appears to be a singularity problem.
This warning is generated because MATLAB is trying to reduce the time step to a really small value in order to counter the abrupt change due to the discontinuity. For sharp discontinuities, it might not be possible to avoid this warning and get the expected result. However, for non-discontinuous inputs, here are the following workarounds:
  1. Set the relative and absolute tolerances to a higher number than the default.
Refer the following workaround to achieve the above goal:
% ode solver
options = odeset('RelTol', 1e-6, 'AbsTol', 1e-9);
sol = ode45(myfun,tspan,y0,options);
2. Using ODE15s or ODE23s to solve the stiff equation.
3. Checking the function being passed into the ODE solver to ensure there are no minor errors in the expression.
You can refer to the following documentation to learn more about choosing an ODE solver:
I hope you find this helpful!


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!