MATLAB: Graph intersection of 3 curves

curvesgraphintersectionploting

I have 3 functions:
x=-1:0.001:1;
y1=((3*x.^2)-1)/2;
y2=((5*x.^3)-(3*x))/2;
y3=((35*x.^4)-(30*x.^2)+3)/8;
plot(x,y1,'g-',x,y2,'r–',x,y3,'b-.');
I need to find all the interception points in the graphic.
The result should look like this:

Best Answer

This was a fun project!
y1 = @(x) ((3*x.^2)-1)/2;
y2 = @(x) ((5*x.^3)-(3*x))/2;
y3 = @(x) ((35*x.^4)-(30*x.^2)+3)/8;
e0 = linspace(-1,1,10);
for k1 = 1:length(e0)
y1y2(k1) = fzero(@(x) (y1(x)-y2(x)), e0(k1));
y1y3(k1) = fzero(@(x) (y1(x)-y3(x)), e0(k1));
y2y3(k1) = fzero(@(x) (y2(x)-y3(x)), e0(k1));
end
y1y2 = unique(round(y1y2*1E+3)/1E+3);
y1y3 = unique(round(y1y3*1E+3)/1E+3);
y2y3 = unique(round(y2y3*1E+3)/1E+3);
x = linspace(-1,1);
figure(1)
plot(x,y1(x),'g-',x,y2(x),'r--',x,y3(x),'b-.');
hold on
plot(y1y2, y1(y1y2), 'kp', 'MarkerSize',8, 'MarkerFaceColor','y')
plot(y1y3, y3(y1y3), 'kp', 'MarkerSize',8, 'MarkerFaceColor','y')
plot(y2y3, y2(y2y3), 'kp', 'MarkerSize',8, 'MarkerFaceColor','y')
hold off
This might be written to be more efficient, but it works!
Related Question