필터 지우기
필터 지우기

Im not sure as to why this code wont stop running. Can some one help

조회 수: 1 (최근 30일)
Joshua Ekwueme
Joshua Ekwueme 2021년 11월 4일
댓글: Rik 2021년 11월 4일
k=1.584;
m=1.692;
c=8.84;
Xo=0.2458874;
t1=6.838;
x=0.37328;
Wn=sqrt(k/m);
Ccrit=2*sqrt(k*m);
Dr=c/Ccrit;
n1=5;
x_left1=4;
x_right1=5.5;
abs_error=0.0000011;
loop_counter1=1;
Vo=0;
for i=1:n1
while abs_error>0.000001
loop_counter1=loop_counter1+1;
Vo=x_left1;
[x_t,a1,a2]=bis_eq(Vo,Dr,Wn,Xo,t1);
f_left=x_t-x;
Vo=x_right1;
[x_t,a1,a2]=bis_eq(Vo,Dr,Wn,Xo,t1);
f_right=x_t-x;
x_mid=(x_left+x_right)/2;
Vo=x_mid;
[x_t,a1,a2]=bis_eq(Vo,Dr,Wn,Xo,t1);
f_mid=x_t-x;
if f_left*f_mid<=0
x_right1=x_mid;
elseif f_left*f_mid>0
x_left1=x_mid;
f_left=f_mid;
end
est=(x_left1+x_right1)/2;
abs_error=(x_right1-x_left1)/2;
disp(est)
end
end
  댓글 수: 1
Rik
Rik 2021년 11월 4일
You didn't post bis_eq, so we can't actually test your code.
Also note that you don't reset the error variable after your while loop, so it will only run for i=1.

댓글을 달려면 로그인하십시오.

답변 (1개)

Yongjian Feng
Yongjian Feng 2021년 11월 4일
Print out abs_error as well after you print est.
Most likely abs_error is always larger than 0.000001.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by