Find points of intersection and area between two curves,

Hi all,
Being reasonably new to Matlab I'm stuck on how to find both answers. I can plot the two curves on a graph but don't know how to calculate points of intersection and area between them. The curves concerned are as follows:
y = (3x^2)+2x-10
&
y = sin(5x+c2) when c2=9 (c2 calculated in a previous question)
any advice would be great, thanks!

 Accepted Answer

I would use the fzero function to calculate the intersections:
x = linspace(-3,3);
y1 = @(x) (3*x.^2)+2.*x-10;
c2=9;
y2 = @(x) sin(5*x+c2);
for k1 = 1:2
x0 = 5*(-1)^k1;
xint(k1) = fzero(@(x) y1(x)-y2(x), x0);
end
figure(1)
plot(x, y1(x))
hold on
plot(x, y2(x))
plot(xint, y1(xint), 'pb')
grid
I will leave the area calculation to you.

More Answers (3)

OK thank you, but how do I obtain an exact value for the intersection points rather then just estimating it by reading it off the graph?

1 Comment

The ‘xint’ vector has the x-coordinates of the intersections. Since they are common to both curves, you can find the y-values by substituting in either function. In the ‘figure(1)’ plot, I did this with ‘y1(xint)’.
Run my code (copy it and paste it to your MATLAB Editor) to see how it works.
The integral is easy to calculate, using a similar idea to what I did in the fzero call. (I already did it.) Give it a go, and if you have problems, I’ll help you get it running.

Sign in to comment.

I understand it's not 100% exact points but just i need to obtain the coordinates for them

2 Comments

Did you even take a look in Start Strider's code ?
xint(1) and xint(2) are the intersection points of the two curves.
Best wishes
Torsten.

Sign in to comment.

As I said I'm reasonably new to matlab and didn't know you could just type xint(1) after to get the exact value... but now I do, thanks all!

Categories

Find more on Scripts in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!