我就认为两条曲线方程分别为
y1 = 0.2*exp(1)-0.5*x.*cos(4*pi*x);
y2 = 2*exp(1)-0.5*x.*cos(pi*x);
运行下面代码即可画出图形并标注交点
- clear
- clc
- x=linspace(-8,8,200);
- y1 = 0.2*exp(1)-0.5*x.*cos(4*pi*x);
- y2 = 2*exp(1)-0.5*x.*cos(pi*x);
- plot(x,y1,'r')
- hold on
- plot(x,y2)
- y1_y2 = diff((y1-y2)>=0);
- id = find(y1_y2);
- xcross = [];
- ycross = [];
- if ~isempty(id)
- fenmu = y2(id)-y2(id+1)+y1(id+1)-y1(id);
- xcross = (x(id+1).*(y2(id)-y1(id))+x(id).*(y1(id+1)-y2(id+1)))./fenmu;
- ycross = (y1(id+1).*y2(id)-y1(id).*y2(id+1))./fenmu;
- end
- [xcross' ycross']
- plot(xcross, ycross, 'o')
复制代码
图形如下 |