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
subplot(3,1,i);
plot(sol.x,sol.y(i,:));
xlabel('time');
ylabel('Current');
title(['stator current # ',int2str(i)]);
end
g = figure;
for i=3
plot(sol.x,sol.y(i,:)*30/pi);
xlabel('time,s');
ylabel('Speed, rpm');
title('Mechanical Angular Speed');
end
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
I(i,1)=y(i);
end
Te = 1/2*p*I'*Cn*I
if t<0.75
Tl=0;
else
Tl=7.31;
end
V = [1.4142*400/sqrt(3)*cos(Wr*t);
1.4142*400/sqrt(3)*cos(Wr*t+2.*pi/3.);
1.4142*400/sqrt(3)*cos(Wr*t-2.*pi/3.);
(Te-Tl)/inertia;
y(4)]
% 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);
end
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.
  3 Comments
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
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!

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!