While loop doesn't start

조회 수: 19 (최근 30일)
Nader Mohamed
Nader Mohamed 2021년 10월 29일
답변: Walter Roberson 2021년 10월 29일
I'm trying to run a while loop until my error reaches the tolerance. But this loop doesn't start. I tried running it without the while loop (putting it manually the parameters) and it workd, but when I want to loop it it doesnt even start, no errors.. My goal here is to find the paramateres b and k that match the minimum error between the sampled solution (y2data) and the numerical solution
toll = 10e-12;
b = 0;
k = 0;
err = 0;
res = [];
while(err>toll)
findbk = @(t,y) [y(3);y(4);k/J1 * y(2) - k/J1 * y(1);T0/J2 - b*y(4)/J2 - (k/J2)*(y(2)-y(1))];
[t,y] = ode45(@(t,y) findbk(t,y),[0:0.01:10],[0,0,0,0]);
fun = @(b,k) T0/J2 - (b/J2).*y(:,4) - ((k/J2).*(y(:,2)-y(:,1)));
err = abs(norm(y2data - fun(b,k)));
res = [res;err];
b = b + 0.01;
k = k + 0.1;
end

채택된 답변

Walter Roberson
Walter Roberson 2021년 10월 29일
0>1e-12 is false.
Initialize error to infinity

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by