Find intersecting points of two functions

2 ビュー (過去 30 日間)
Isaac Fife
Isaac Fife 2020 年 3 月 17 日
コメント済み: Sajeer Modavan 2020 年 3 月 19 日
I need to find the intersecting points ofr two functions but it only works for simple functions
If I try it with trig funtions it tells me my index exceeds my number of arrays, how do I fix this???
dx = 1/10;
x = 0:dx:10;
fun_1 = (power(x,2));
fun_2 = (x);
find (x==1)
difference = abs(fun_1 - fun_2);
sub_script = find (difference == min(difference) );
%%
difference = abs(fun_1 - fun_2);
min_difference = min(difference);
intersect_subs = find(difference == min(difference) );
sub_1 = intersect_subs(1);
sub_2 = intersect_subs(2); %tells me the error is here..
x_intersect_1 = x(sub_1);
x_intersect_2 = x(sub_2);
point_1 = fun_1(sub_1);
point_2 = fun_2(sub_2);
figure(1)
plot(x, fun_1,...
x, fun_2,...
x_intersect_1, point_1, 'ko',...
x_intersect_2, point_2, 'ko', 'Markersize', 7)
  5 件のコメント
Isaac Fife
Isaac Fife 2020 年 3 月 18 日
They also intersect at (0,0), but the problem is
when I change it to something like sin(x) and (x-2)^2 it just wont run and says my index exceeds my number of arrays.
dx = 1/100;
x = 0:dx:10;
fun_1 = power((x-2),2);
fun_2 = sin(x);
find (x==1)
difference = abs(fun_1 - fun_2);
%sub_script = find (difference == min(difference) );
%%
min_difference = min(difference);
intersect_subs = find(difference == min(difference) );
sub_1 = intersect_subs(1);
sub_2 = intersect_subs(2);
x_intersect_1 = x(sub_1);
x_intersect_2 = x(sub_2);
point_1 = fun_1(sub_1);
point_2 = fun_2(sub_2);
figure(1)
plot(x, fun_1,...
x, fun_2,...
x_intersect_1, point_1, 'ko',...
x_intersect_2, point_2, 'ko', 'Markersize', 7)
darova
darova 2020 年 3 月 18 日
Can't you just use polyxpoly?

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

回答 (1 件)

Sajeer Modavan
Sajeer Modavan 2020 年 3 月 18 日
clc
clear
dx = 1/100;
x = 0:dx:2;
fun_1 = (power(x,2));
fun_2 = (x);
intersect_subs = find(round(fun_1,1) == round(fun_2,5));
figure(1)
plot(x, fun_1,...
x, fun_2,...
x(intersect_subs), fun_1(intersect_subs), 'ko', 'Markersize', 7)
%%
dx = 1/100;
x = 0:dx:2;
fun_1 = (cos(x));
fun_2 = (x);
intersect_subs = find(round(fun_1,1) == round(fun_2,1));
figure(2)
plot(x, fun_1,...
x, fun_2,...
x(intersect_subs), fun_1(intersect_subs), 'ko', 'Markersize', 7)
  1 件のコメント
Sajeer Modavan
Sajeer Modavan 2020 年 3 月 19 日
is it solved your problem?

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by