Hhow to enhance smoothness of graph?

2 views (last 30 days)
shiv gaur
shiv gaur on 23 Jan 2022
Commented: shiv gaur on 23 Jan 2022
function metal1
T2=1e-9:1e-10:1e-6;
for j=1:numel(T2)
t2 = T2(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,t2) - f(p0,t2))/h1;
DELTA2 = (f(p2,t2) - f(p1,t2))/h2;
d = (DELTA2 - DELTA1)/(h2 + h1);
i=3;
while i <= N0
b = DELTA2 + h2*d;
D = (b^2 - 4*f(p2,t2)*d)^(1/2);
if abs(b-D) < abs(b+D)
E = b + D;
else
E = b - D;
end
h = -2*f(p2,t2)/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,t2) - f(p0,t2))/h1;
DELTA2 = (f(p2,t2) - f(p1,t2))/h2;
d = (DELTA2 - DELTA1)/(h2 + h1);
i=i+1;
end
if i > N0
formatSpec = string('The method failed after N0 iterations,N0= %d ');
fprintf(formatSpec,N0);
end
P(j)=abs(imag(p)*8.57e5);
% P(j)=real((p));
end
plot(T2,P)
end
%--------------------------------------------------------------------------------
function y=f(x,t2)
%t2=1e-9;
k0=(2*pi/0.6328)*1e6;
n1=1.521;
%n2=2.66;
n2=4.1-1i*0.211;
ns=1.512;
%n2=1.2-1i*7;
nc=1;
k1=k0*sqrt(n1.^2-x.^2);
k2=k0*sqrt(n2.^2-x.^2);
t1=2e-6;
m11= cos(t1*k1)*cos(t2*k2)-(k2/k1)*sin(t1*k1)*sin(t2*k2);
m12=(1/k2)*(cos(t1*k1)*sin(t2*k2)*1i) +(1/k1)*(cos(t2*k2)*sin(t1*k1)*1i);
m21= (k1)*cos(t2*k2)*sin(t1*k1)*1i +(k2)*cos(t1*k1)*sin(t2*k2)*1i;
m22=cos(t1*k1)*cos(t2*k2)-(k1/k2)*sin(t1*k1)*sin(t2*k2);
%gs=(x.^2-ns.^2)*k0.^2;
%gc= (x.^2-nc.^2)*k0.^2;
gs=k0*sqrt(x.^2-ns.^2);
gc=k0*sqrt(x.^2-nc.^2);
y= 1i*(gs*m11+gc*m22)-m21+gc*gs*m12 ;
end
This is the running program but we are not getting the fine graph just like that in the attach file.
  9 Comments
shiv gaur
shiv gaur on 23 Jan 2022
p is the root of the equation and where to write these sgolayfilt (): in program
shiv gaur
shiv gaur on 23 Jan 2022
how to use sgolayfilt(P,31); in this program to smooth the graph

Sign in to comment.

Answers (0)

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!