clc
rounding = 6;
rn = 1.3;
f = 0.5;
ap = 0.2;
po = 10;
dx = 10^(-rounding);
lambda = 0;
gamma = -8;
Kr = 51;
Kr1 = 51;
xa = (rn*(sin(Kr)))*-1;
xb = rn*(sin(Kr1));
ya = (xa*(tan(Kr)))+(rn/(cos(Kr)))-rn;
N = 10^(rounding);
xpA = xa - (0:N-1)*dx;
xpA = xpA';
xpA = sort(xpA);
xpA = round(xpA,rounding);
ypA = (xpA*tan(Kr))+(rn/(cos(Kr)))-rn;
ypA = sort(ypA);
ypA = round(ypA,rounding);
xpB = xb + (0:N-1)*dx;
xpB = xpB';
xpB = round(xpB,rounding);
ypB = (-xpB*tan(Kr1))+(rn/(cos(Kr1)))-rn;
ypB = round(ypB,rounding);
N1 = 2*N;
xk1 = xa + (1:N1)*dx;
xk1 = round(xk1,rounding);
xk1 = xk1';
[c,d]= intersect(xk1,min(xpB));
xk = xa +(1:d-1)*dx;
xk = round(xk,rounding);
xk = xk';
yk = (sqrt((rn^2)-(xk.^2)))-rn;
yk = round(yk,rounding);
X = [xpA;xk;xpB];
Y = [ypA;yk;ypB];
b = po-ap;
x = X(1);
X1 = X-x;
Y1 = Y+b;
X2 = X1+f;
Y2 = Y1;
[Y1max,Y1ix] = max(Y1);
[Y2max,Y2ix] = max(Y2);
Xi = linspace(X1(Y1ix), X2(Y2ix), 100);
Y1i = interp1(X1,Y1,Xi);
Y2i = interp1(X2,Y2,Xi);
Ydif = sort(Y2i-Y1i);
[val,ind1] = min(abs(Y2i-Y1i));
Xq = interp1(Ydif, Xi, 0);
Yq = interp1(Xi, Y1i, Xq);
Xq_distance_to_first_peak = Xq - X1(Y1ix);
figure(1)
plot(X1,Y1)
hold on
plot(X2,Y1)
plot(Xq, Yq, 'sg', 'MarkerSize', 10)
hold off
text(Xq, Yq, sprintf('\\uparrow\nX = %.4f\nY = %.4f',Xq,Yq), 'HorizontalAlignment','center', 'VerticalAlignment','top')
ind1 = find(X1>X1(Y1ix)-Xq_distance_to_first_peak & X1<X1(Y1ix)+Xq_distance_to_first_peak);
Xi1 = X1(ind1);
Y1ii = interp1(X1,Y1,Xi1);
ind2 = find(X2>X2(Y2ix)-Xq_distance_to_first_peak & X2<X2(Y2ix)+Xq_distance_to_first_peak);
Xi2 = X2(ind2);
Y2ii = interp1(X2,Y2,Xi2);
figure(2)
plot(Xi1,Y1ii)
hold on
plot(Xi2,Y2ii)
Best Answer