matlab 求代数方程组 a*x^2+b*x+c=0 x+y=0 关于x,y的解,并分别绘制x和y关于b和c的图像(a视作常数)

如题所述

1. 求代数方程组的解:

>> [x,y]=solve('a*x^2+b*x+c=0','x+y=0','x,y')

 

x =

  1/2/a*(-b+(b^2-4*a*c)^(1/2))

 1/2/a*(-b-(b^2-4*a*c)^(1/2))


 y =

  -1/2/a*(-b+(b^2-4*a*c)^(1/2))

 -1/2/a*(-b-(b^2-4*a*c)^(1/2))

 >> 

2. 从上面的解可以看出,x,y都有两组解且x,y互为相反数。

假设a=1,这里有两种方法绘制x,y关于b,c的图像:

(1)隐函数绘图

x1=subs(x(1),'a',1);

x2=subs(x(2),'a',1);

y1=subs(y(1),'a',1);

y2=subs(y(2),'a',1);

figure

po=get(gcf,'position');

set(gcf,'position',[po(1)-0.5*po(3) po(2) 2*po(3) po(4)]);

subplot(121)

ezsurf(x1,[-10 10])

hold on

ezsurf(x2,[-10 10])

subplot(122)

ezsurf(y1,[-10 10])

hold on

ezsurf(y2,[-10 10])


(2)根据方程式直接绘图

>> a=1;

>> [b,c]=meshgrid(-10:0.5:10);

>> delta=b.^2-4*a*c;

>> delta(delta<0)=NaN;

>> x1=0.5/a*(-b+sqrt(delta));

>> x2=0.5/a*(-b-sqrt(delta));

>> y1=-x1;

>> y2=-x2;

>> figure

>> po=get(gcf,'position');

>> set(gcf,'position',[po(1)-0.5*po(3) po(2) 2*po(3) po(4)]);

>> subplot(121)

>> surf(b,c,x1)

>> hold on

>> surf(b,c,x2)

>> xlabel('b');ylabel('c');zlabel('x')

>> subplot(122)

>> surf(b,c,y1)

>> hold on

>> surf(b,c,y2)

>> xlabel('b');ylabel('c');zlabel('y')

温馨提示:答案为网友推荐,仅供参考