how to find the root of transcedental equation while loop

5 次查看(过去 30 天)
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;
t3=1e-9;
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;
y=-(k2)*t2+atan(k1/1i*k2)+atan((k3/k2)*tan(atan(k4/1i*k2)-k3*t3))+m*pi;
how to calculate the root of equation i.e the vaue of x numerically by while loop

回答(1 个)

Walter Roberson
Walter Roberson 2022-2-17
format long g
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;
t3=1e-9;
tol = 1e-12;
n = 1;
x = rand
x =
0.599324733046148
y = inf;
while n < 5 & abs(y) > tol
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);
y=-(k2)*t2+atan(k1/1i*k2)+atan((k3/k2)*tan(atan(k4/1i*k2)-k3*t3))+m*pi;
[n, x, y]
n = n + 1;
end
ans =
1 + 0i 0.599324733046148 + 0i -17.6929697847717 + 7.90103155130006e-07i
ans =
2 + 0i 0.599324733046148 + 0i -17.6929697847717 + 7.90103155130006e-07i
ans =
3 + 0i 0.599324733046148 + 0i -17.6929697847717 + 7.90103155130006e-07i
ans =
4 + 0i 0.599324733046148 + 0i -17.6929697847717 + 7.90103155130006e-07i
All of the results are the same because you have not defined any way for x to change.
  5 个评论
shiv gaur
shiv gaur 2022-2-17
from muller method ans is different why is so
here is program
function kps3
T3 = 1e-9:1e-9:1e-6;
for j=1:numel(T3)
t3 = T3(j);
p0 = 0.5;
p1 = 1;
p2 = 1.5;
TOL = 10^-8;
N0 = 100; format long
h1 = p1 - p0;
h2 = p2 - p1;
DELTA1 = (f(p1,t3) - f(p0,t3))/h1;
DELTA2 = (f(p2,t3) - f(p1,t3))/h2;
d = (DELTA2 - DELTA1)/(h2 + h1);
i=3;
while i <= N0
b = DELTA2 + h2*d;
D = (b^2 - 4*f(p2,t3)*d)^(1/2);
if abs(b-D) < abs(b+D)
E = b + D;
else
E = b - D;
end
h = -2*f(p2,t3)/E;
p = p2 + h;
if abs(h) < TOL
%disp(p)
break
end
p0 = p1;
p1 = p2;
p2 = p;
h1 = p1 - p0;
h2 = p2 - p1;
DELTA1 = (f(p1,t3) - f(p0,t3))/h1;
DELTA2 = (f(p2,t3) - f(p1,t3))/h2;
d = (DELTA2 - DELTA1)/(h2 + h1);
i=i+1;
end
if i > N0
formatSpec = string('The method failed after N0 iterations,N0= %d \n');
fprintf(formatSpec,N0);
end
P(j)=real(p);
end
plot(T3,P)
end
function y=f(x, t3)
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;
m=0;
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);
y=(k2)*t2-atan(k1/1i*k2)-atan((k3/k2)*tan(atan(k4/1i*k2)-k3*t3))+m*pi;
end
why results are so different using while loop pl sort out the problem using this while loop
shiv gaur
shiv gaur 2022-2-17
I think root will be same for both program use while loop or muller

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops 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