Im not sure as to why this code wont stop running. Can some one help
2 ビュー (過去 30 日間)
古いコメントを表示
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
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
2021 年 11 月 4 日
Print out abs_error as well after you print est.
Most likely abs_error is always larger than 0.000001.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!