Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Rik
Rik il 4 Nov 2021
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.

Accedi per commentare.

Risposte (1)

Yongjian Feng
Yongjian Feng il 4 Nov 2021
Print out abs_error as well after you print est.
Most likely abs_error is always larger than 0.000001.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by