Intersections between two discretised functions

6 ビュー (過去 30 日間)
EDOARDO GIOVANNI
EDOARDO GIOVANNI 2023 年 12 月 8 日
コメント済み: Dyuman Joshi 2023 年 12 月 11 日
Hi Everybody, I have the following problem:
I have two vectors:
  • v1 = list of values representing a discretised non monotonic function
  • v2 = list of values representing a constant and horizontal line
v1 has no analytical model. It's just a vector containing the values a function assumes in a given interval.
To make everything clearer, let's consider the following case:
  • v1 = list of 100 values representing a parabola: y= x^2, with x=linspace(-5, +5, 100)
  • v2 = ones(1,100)
f = @(x) x.^2;
values = linspace(-5, 5, 100);
v1 = f(values);
v2 = ones(1,100);
Clearly, the intersection points are two, for x1=-1 and x2=+1.
Now let's forget about the fact that we had the analytical expression for v1 and let's just consider the vector itself.
How can I implement this on Matalb for a generical vector v1 which is not monotonic and is supposed to have two intersection points with v2? I tried doing something with interp1 but couldn't figure it out.
Thanks a lot to whoever will help me!
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 12 月 8 日
If you look in the File Exchange you will find at least 4 contributions for finding curve intersections.

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

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 12 月 8 日
You can use FEX submissions for this, I have run these two submissions below - InterX, intersections as example -
You can also find many answers on this forum, which utilize interp1 to get intersection points of two curves.
x = linspace(-5, 5);
v1 = x.^2;
v2 = ones(size(x));
P1 = InterX([x;v1],[x;v2])
P1 = 2×2
-0.9988 0.9988 1.0000 1.0000
[x0, y0] = intersections(x, v1, x, v2)
x0 = 2×1
-0.9988 0.9988
y0 = 2×1
1 1
  2 件のコメント
EDOARDO GIOVANNI
EDOARDO GIOVANNI 2023 年 12 月 10 日
I didn't know of the existance of these submissions, thank you Dyuman.
Dyuman Joshi
Dyuman Joshi 2023 年 12 月 11 日
You're Welcome!

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

その他の回答 (1 件)

Matt J
Matt J 2023 年 12 月 8 日
編集済み: Matt J 2023 年 12 月 8 日
f = @(x) x.^2;
x = linspace(-5, 5, 100);
v1 = f(x);
v2 = ones(size(v1));
X0=x(diff(sign(v1-v2))~=0);
X=nan(size(X0));
for i=1:numel(X)
X(i)=fzero(@(t)interp1(x,v1-v2,t,'cubic'), X0(i));
end
X %solutions
X = 1×2
-1.0000 1.0000

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by