problem in plot while loop

2 ビュー (過去 30 日間)
shiv gaur
shiv gaur 2022 年 2 月 16 日
コメント済み: shiv gaur 2022 年 2 月 16 日
k0=(2*pi/0.6328)*1e6;
t2=1.5e-6;
n1=1.512;n2=1.521;n3=4.1-1i*0.211;
n4=1;
m=0;
x=1.512;
t3=1e-9:1e-6;
k1=k0*sqrt(n1^2-x^2);
k2=k0*sqrt(n2^2-x^2);
k3=k0*sqrt(n3^2-x^2);
k4=k0*sqrt(n4^2-x^2);
tol = 1e-12;
n = 1;
while 1
x_new =-(k2)*t2+atan(k1/1i*k2)+atan((k3/k2)*tan(atan(k4/1i*k2)-k3*t3))+m*pi;
if abs(x_new-x) < tol, break; end
x =x_new;
k1=k0*sqrt(n1^2-x^2);
k2=k0*sqrt(n2^2-x^2);
k3=k0*sqrt(n3^2-x^2);
k4=k0*sqrt(n4^2-x^2);
n=n+1;
end
pl plot graph between t3 vs x_new
where x_new is the root of the equation
  8 件のコメント
Walter Roberson
Walter Roberson 2022 年 2 月 16 日
What do the % mean in your formula for x_new?
shiv gaur
shiv gaur 2022 年 2 月 16 日
k0=(2*pi/0.6328)*1e6;
t2=1.5e-6;
n1=1.512;n2=1.521;n3=4.1-1i*0.211;
n4=1;
m=0;
x=1.512;
t3=1e-9:1e-6;
k1=k0*sqrt(n1^2-x^2);
k2=k0*sqrt(n2^2-x^2);
k3=k0*sqrt(n3^2-x^2);
k4=k0*sqrt(n4^2-x^2);
tol = 1e-12;
n = 1;
while 1
x_new =-(k2)*t2+atan(k1/1i*k2)+atan((k3/k2)*tan(atan(k4/1i*k2)-k3*t3))+m*pi;
if abs(x_new-x) < tol, break; end
x =x_new;
k1=k0*sqrt(n1^2-x^2);
k2=k0*sqrt(n2^2-x^2);
k3=k0*sqrt(n3^2-x^2);
k4=k0*sqrt(n4^2-x^2);
n=n+1;
end
% is nothing that is edited code not able to plot help using while loop x is the root of the equation xnew is the transedental equation

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

採用された回答

Jan
Jan 2022 年 2 月 16 日
k0 = 2 * pi / 0.6328 * 1e6;
t2 = 1.5e-6;
n1 = 1.512;
n2 = 1.521;
n3 = 4.1-1i*0.211;
n4 = 1;
m = 0;
x = 1.512;
t3 = 1e-9; % ??? :1e-6;
tol = 1e-12;
n = 1;
while 1
k1 = k0 * sqrt(n1^2 - x^2);
k2 = k0 * sqrt(n2^2 - x^2);
k3 = k0 * sqrt(n3^2 - x^2);
k4 = k0 * sqrt(n4^2 - x^2);
x_new = -k2 * t2 + atan(k1/1i*k2) + ...
atan((k3/k2) * tan(atan(k4/1i*k2) - k3*t3)) + m*pi;
if abs(x_new-x) < tol || n > 1e4, break; end
x = x_new;
n = n + 1;
end
n
The formula does not converge.
  2 件のコメント
shiv gaur
shiv gaur 2022 年 2 月 16 日
k0=(2*pi/0.6328)*1e6;
t2=1.5e-6;
n1=1.512;n2=1.521;n3=4.1-%i*0.211;
n4=1;
m=0;
x=1;
t3=linspace(1e-9,1e-6,20);
k1=k0*sqrt(n1^2-x.^2);
k2=k0*sqrt(n2^2-x.^2);
k3=k0*sqrt(n3^2-x^2);
k4=k0*sqrt(n4^2-x.^2);
tol = 1e-12;
n = 0;
while (n<=20)
x_new =-(k2).*t2+atan(k1./%i*k2)+atan((k3./k2).*tan(atan(k4./%i*k2)-k3.*t3))+m*%pi;
if abs(x_new-x) < tol, break; end
x =x_new;
k1=k0*sqrt(n1^2-x.^2);
k2=k0*sqrt(n2^2-x.^2);
k3=k0*sqrt(n3^2-x.^2);
k4=k0*sqrt(n4^2-x.^2);
n=n+1;
end
plot(t3,x_new)
this is the program pl plot the graph
shiv gaur
shiv gaur 2022 年 2 月 16 日
why this is not converging where x is the root of function x_new

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by