matlab求2曲线交点(含参数)

在同一坐标中绘制下列两条曲线并标注两曲线交叉点
(1)y=2x-0.5
(2)x=sin(3t)cos(t)
y=sin(3t)sin(t)
0<=t<=pi

程序代码如下:

clc;clear;close all;
t=0:0.01:pi;
x=sin(3*t).*cos(t);
y1=2*x-0.5;
y2=sin(3*t).*sin(t);
plot(t,y1,t,y2);grid;
delta_y=y1-y2;
% figure;stem(delta_y);
j=1;
for i=1:length(t)-1
if delta_y(i)*delta_y(i+1)<0
position(j)=i+1;
j=j+1;
end
end
hold on;
plot(t(position),y1(position),'ro');
title('两条曲线相交');
xlabel('x');ylabel('y');
h = legend('y1','y2');
温馨提示:答案为网友推荐,仅供参考
相似回答