how to calculate by tol and while loop

9 ビュー (過去 30 日間)
shiv gaur
shiv gaur 2022 年 2 月 17 日
編集済み: Walter Roberson 2022 年 2 月 17 日
k0=(2*pi/0.6328)*1e6;
t2=1.5e-6;
n1=1.512;n2=1.521;
x=2; % approximation
k1=k0*sqrt(n1^2-x.^2);k2=k0*sqrt(n2^2-x.^2);
tol = 1e-12;
n = 1;
while (n<=200)
y =-(k2).*t2+atan(k1./1i*k2)
if abs(ynew-y) < tol, break; end
x =xnew;
k1=k0*sqrt(n1^2-x.^2);
k2=k0*sqrt(n2^2-x.^2);
n=n+1;
end
disp(xnew)
how to use while loop in this program and f(abs ) value use

回答 (1 件)

Voss
Voss 2022 年 2 月 17 日
Your while loop might have a structure like this:
tol = 1e-12;
err = Inf;
n = 1;
while n <= 200 && err > tol
% get new estimate (of whatever you are trying to calculate)
% calculate updated error, err
n = n+1;
end
disp(n)
201
  1 件のコメント
shiv gaur
shiv gaur 2022 年 2 月 17 日
編集済み: Walter Roberson 2022 年 2 月 17 日
k0=(2*pi/0.6328)*1e6;
t2=1.5e-6;
n1=1.512;n2=1.521
k1=k0*sqrt(n1^2-x^2);
k2=k0*sqrt(n2^2-x^2);
y=-(k2)*t2+atan(k1/1i*k2)
sir we have to find the value of x from k1,k2 ,y equation so I am not able
so pl apply this in program

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by