フィルターのクリア

How to find the intersection values?

3 ビュー (過去 30 日間)
GULZAR
GULZAR 2023 年 8 月 17 日
編集済み: Torsten 2023 年 8 月 17 日
How to find the intersection values of line(black) and the curve(blue)
clc
close all
d1 = 0.4;d2 = 0.6;d = d1 + d2;
n1 = sqrt(12);n2 = 1;
lambda = linspace(400e-3,800e-3, 100000);
D1 = (2*pi*n1*d1)./lambda;D2 = (2*pi*n2*d2)./lambda;
RHS = cos(D1).*cos(D2) - 0.5*(n1^2+n2^2)/(n1*n2) * sin(D1) .*sin(D2);
plot(lambda,RHS)
hold on
yline(-1);
hold off
hold on
yline(1);

採用された回答

Bruno Luong
Bruno Luong 2023 年 8 月 17 日
d1 = 0.4;d2 = 0.6;d = d1 + d2;
n1 = sqrt(12);n2 = 1;
lambda = linspace(400e-3,800e-3, 100000);
D1 = (2*pi*n1*d1)./lambda;D2 = (2*pi*n2*d2)./lambda;
RHS = cos(D1).*cos(D2) - 0.5*(n1^2+n2^2)/(n1*n2) * sin(D1) .*sin(D2);
plot(lambda,RHS)
hold on
for yx = [-1 1]
yline(yx);
ys = RHS-yx;
i = find(ys(1:end-1).*ys(2:end) <= 0);
% linear interpolation
i1 = i; ss1 = ys(i1);
i2 = i1 + 1; ss2 = ys(i2);
w = ss2./(ss2-ss1);
xx = w.*lambda(i1) + (1-w).*lambda(i2);
plot(xx, yx+zeros(size(xx)), 'rx')
end
  2 件のコメント
GULZAR
GULZAR 2023 年 8 月 17 日
Thank you. And how to show the intersection points...
Torsten
Torsten 2023 年 8 月 17 日
編集済み: Torsten 2023 年 8 月 17 日
xx
at the end of the for-loop.

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

その他の回答 (1 件)

Torsten
Torsten 2023 年 8 月 17 日
format long
d1 = 0.4;d2 = 0.6;d = d1 + d2;
n1 = sqrt(12);n2 = 1;
D1 = @(lambda)(2*pi*n1*d1)./lambda;D2 = @(lambda)(2*pi*n2*d2)./lambda;
RHS = @(lambda)cos(D1(lambda)).*cos(D2(lambda)) - 0.5*(n1^2+n2^2)/(n1*n2) * sin(D1(lambda)) .*sin(D2(lambda));
% Case -1
start = [0.42,0.45,0.56,0.59,0.72];
offset = -1;
rhs = @(lambda) RHS(lambda)-offset;
for i = 1:numel(start)
sol(i) = fsolve(rhs,start(i),optimset('Display','none'));
end
sol
sol = 1×5
0.425911883383464 0.453366368933051 0.559061333603378 0.580387744533463 0.740288322697614
% Case 1
start = [0.4,0.47,0.52,0.63,0.67];
offset = 1;
rhs = @(lambda) RHS(lambda)-offset;
for i = 1:numel(start)
sol(i) = fsolve(rhs,start(i),optimset('Display','none'));
end
sol
sol = 1×5
0.398347393959160 0.476820539375385 0.520624847917834 0.636196969306721 0.680659944575321

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by