Find intersecting points of two functions

2 visualizaciones (últimos 30 días)
Isaac Fife
Isaac Fife el 17 de Mzo. de 2020
Comentada: Sajeer Modavan el 19 de Mzo. de 2020
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 comentarios
Isaac Fife
Isaac Fife el 18 de Mzo. de 2020
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 el 18 de Mzo. de 2020
Can't you just use polyxpoly?

Iniciar sesión para comentar.

Respuestas (1)

Sajeer Modavan
Sajeer Modavan el 18 de Mzo. de 2020
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)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by