How to use spline interpolation to find intersection point of two lines.

41 ビュー (過去 30 日間)
PetronasAMG
PetronasAMG 2021 年 11 月 9 日
コメント済み: PetronasAMG 2021 年 11 月 9 日
Hi, Just new to matlab and still trying to understand spline interpolation. Although we can eye ball the interspection point, how do you use spline interpolation to find the exact interspection point? please help!
x = [-10 2];
y1 = -x
y1 = 1×2
10 -2
y2 = x+6;
plot(x,y1), hold on;
plot(x,y2);

採用された回答

H R
H R 2021 年 11 月 9 日
How about this?
clc
clear all
x = -10:1:1;
y1=-x;
y2=x+6;
%spline1
s1 = spline(x,y1);
%spline 2
s2=spline(x,y2);
% find zeros
x0 = fzero(@(x) (ppval(s1,x)-ppval(s2,x)), 0)
  1 件のコメント
PetronasAMG
PetronasAMG 2021 年 11 月 9 日
also is it possible to draw a red dashline from x axis to the intersection point?

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

その他の回答 (1 件)

Matt J
Matt J 2021 年 11 月 9 日
編集済み: Matt J 2021 年 11 月 9 日
If they are straight lines, I'm not sure why you would want to use splines.
x = [-10 2];
y1 = -x;
y2 = x+6;
P=[x,x;y1 y2; 1 1 1 1 ];
p=cross( cross(P(:,1),P(:,2)) , cross(P(:,3),P(:,4)) );
p=p(1:2).'/p(3) %intersection point
p = 1×2
-3 3

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by