I got such an error while running this code.
2 ビュー (過去 30 日間)
古いコメントを表示
%x'(t)=y(t)+0.2*x(t)*y(t)*(x(t)+y(t)*cot(t))/(y(t)^2-q)
%y'(t)=-x(t)+(1-0.2*y(t)^2)*(x(t)+y(t)*cot(t))/(y(t)^2-1)
function dx=Untitled3(t,x)
dx(1)=x(2)+0.2*x(1)*x(2)*(x(1)+x(2)*cotd(x(3)))/(x(2)^2-1);
dx(2)=-x(1)+(1-0.2*x(2))*(x(1)+x(2)*cotd(x(3)))/(x(2)^2-1);
dx(3)=1;
dx=dx';
end
I run the code as
[T,Y]=ode45(@Untitled3,[0:0.2:10],[3.228,1.4667,19.72])
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 件のコメント
John D'Errico
2018 年 5 月 2 日
編集済み: John D'Errico
2018 年 5 月 2 日
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.
回答 (2 件)
Torsten
2018 年 5 月 2 日
dx(2)=-x(1)+(1-0.2*x(2)^2)*(x(1)+x(2)*cotd(x(3)))/(x(2)^2-1);
instead of
dx(2)=-x(1)+(1-0.2*x(2))*(x(1)+x(2)*cotd(x(3)))/(x(2)^2-1);
Best wishes
Torsten.
1 件のコメント
Jan
2018 年 5 月 2 日
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.
Jan
2018 年 5 月 2 日
編集済み: Jan
2018 年 5 月 2 日
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...
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!