matlab绘出sin(x)与cos(x),用‘*’标出其交点

2024-12-20 00:11:21
推荐回答(3个)
回答1:

x = linspace(-pi,pi,1000);

y1 = sin(x);

y2 = cos(x);

plot(x,y1,x,y2);hold on;

id = find(abs(y1-y2)<0.005); % 找到交点

plot(x(id),y1(id),'r*');

回答2:

x = linspace(-pi,pi,1000);
y0= sin(x);
y = cos(x);
plot(x,y1,x,y2);hold on;
id = find(abs(y1-y2)<0.005); % 寻找出交点
plot(x(id),y1(id),'r*');

回答3: