Reputation: 6055
How can I
For simplicity I have taken two very basic curves :
I am able to plot the curves but cannot obtain the intersection point. See the screenshot:
I have tried the solutions proposed in this question but none of them worked for me.
Upvotes: 2
Views: 7890
Reputation:
Regards User. If I may ask, your objective is to obtain the exact point that intersect those two functions, or the nearest point to the intersection point? (the latter using approximation)
Here is an idea :
1) If your discretization : x=0:0.05:2;
do contain the intersection point, you can use the intersect
function in Matlab.
For example
intersect([1,2,3],[4,3,1])
will return a vector with two elements 1
and 3
, the intersection of those two vectors.
To find the intersection point is to find the point x such that y1(x)=y2(x). So apply
yin = intersect(y1,y2);
After this, since your x
is sorted, you should check the value in yin
that has the same index in both y1
and y2
.
The value that satisfy that condition is the intersection point in the y-axis.
2) If your x
does not include the intersection point in x-axis, then use numerical methods. To find the roots of y2-y1
. (or the points where g(x)=y2(x)-y1(x) = 0, since this is as same as y1(x)=y2(x))
You can try these first. Hope this will be useful. Thanks.
Upvotes: 2