필터 지우기
필터 지우기

I got such an error while running this code.

조회 수: 2 (최근 30일)
Rajan Bhandari
Rajan Bhandari 2018년 5월 2일
편집: Jan 2018년 5월 2일
%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
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
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
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
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...

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by