Find points of intersection and area between two curves,
8 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Star Strider
on 19 Feb 2015
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.
0 Comments
More Answers (3)
Liam Nolan
on 2 Mar 2015
1 Comment
Star Strider
on 2 Mar 2015
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.
Liam Nolan
on 2 Mar 2015
2 Comments
Torsten
on 2 Mar 2015
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.
See Also
Categories
Find more on Graph and Network Algorithms 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!