作业帮 > 英语 > 作业

MATLAB如何画出两条多项式曲线相交中间的部分?

来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/05/11 19:58:17
MATLAB如何画出两条多项式曲线相交中间的部分?
这里是两个多项式:
x1^2 - 2*x1*x2 - x1 + x2^2 - 2=0

x1^2 - 2*x1*x2 + x2^2 + 5*x2 - 2=0

他们的图像画出来如图所示.现在需要填充他们之间的部分,也就是画出:
x1^2 - 2*x1*x2 - x1 + x2^2 - 2  <=0
x1^2 - 2*x1*x2 + x2^2 + 5*x2 - 2<=0
说实话,这个题真的是有难度,试试看:
clear all;clc;
syms x1 x2
[s1,s2]=solve('x1^2-2*x1*x2-x1+x2^2-2=0','x1^2-2*x1*x2+x2^2+5*x2-2=0');
s1=double(s1);s2=double(s2);
f1=x1^2-2*x1*x2-x1+x2^2-2;
f2=x1^2-2*x1*x2+x2^2+5*x2-2;
ezplot(f1);hold on;ezplot(f2);
%-------------------------------------------------------------
xt1=-4:0.01:s1(1);
y1=solve('x1^2-2*x1*x2-x1+x2^2-2=0','x2');
y11=subs(y1(1),x1,xt1);
for ii=1:length(xt1)
      h11(ii)=isreal(y11(ii));
      y11(ii)=y11(ii)*h11(ii);
end
gx=min(y11);gy=subs(y1(1),x1,gx);
%-------------------------------------------------------------
xx1=s1(1):-0.01:gx;
yy1=subs(y1(1),x1,xx1);
xx2=gx:0.01:s1(2);
yy2=subs(y1(2),x1,xx2);
xx3=s1(2):-0.01:s1(1);
y2=solve('x1^2-2*x1*x2+x2^2+5*x2-2','x2');
yy3=subs(y2(1),x1,xx3);
xx=[xx1,xx2,xx3];
yy=[yy1,yy2,yy3];
fill(xx,yy,'r');