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

\u5982\u4f55\u7528matlab\u89e3\u65b9\u7a0b\u7ec4

matlab\u4e2d\u89e3\u65b9\u7a0b\u7ec4\u8fd8\u662f\u5f88\u65b9\u4fbf\u7684\uff0c\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4ee3\u6570\u65b9\u7a0b\u7ec4Ax=b(A\u4e3a\u7cfb\u6570\u77e9\u9635\uff0c\u975e\u5947\u5f02)\u7684\u6c42\u89e3\uff0cMATLAB\u4e2d\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a
(1)x=inv(A)*b \u2014 \u91c7\u7528\u6c42\u9006\u8fd0\u7b97\u89e3\u65b9\u7a0b\u7ec4\uff1b

(2)x=A\B \u2014 \u91c7\u7528\u5de6\u9664\u8fd0\u7b97\u89e3\u65b9\u7a0b\u7ec4
PS\uff1a\u4f7f\u7528\u5de6\u9664\u7684\u8fd0\u7b97\u6548\u7387\u8981\u6bd4\u6c42\u9006\u77e9\u9635\u7684\u6548\u7387\u9ad8\u5f88\u591a~
\u4f8b:
x1+2x2=8
2x1+3x2=13
>>A=[1,2;2,3];b=[8;13];
>>x=inv(A)*b
x =
2.00
3.00
>>x=A\B
x =
2.00
3.00\uff1b
\u5373\u4e8c\u5143\u4e00\u6b21\u65b9\u7a0b\u7ec4\u7684\u89e3x1\u548cx2\u5206\u522b\u662f2\u548c3\u3002

\u5bf9\u4e8e\u540c\u5b66\u95ee\u5230\u7684\u7528matlab\u89e3\u591a\u6b21\u7684\u65b9\u7a0b\u7ec4\uff0c\u6709\u7b26\u53f7\u89e3\u6cd5\uff0c\u65b9\u6cd5\u662f\uff1a\u5148\u89e3\u51fa\u7b26\u53f7\u89e3,\u7136\u540e\u7528vpa(F,n)\u6c42\u51fan\u4f4d\u6709\u6548\u6570\u5b57\u7684\u6570\u503c\u89e3.\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a
\u7b2c\u4e00\u6b65:\u5b9a\u4e49\u53d8\u91cfsyms x y z ;
\u7b2c\u4e8c\u6b65:\u6c42\u89e3[x,y,z,]=solve('eqn1','eqn2',,'eqnN','var1','var2','varN');
\u7b2c\u4e09\u6b65:\u6c42\u51fan\u4f4d\u6709\u6548\u6570\u5b57\u7684\u6570\u503c\u89e3x=vpa(x,n);y=vpa(y,n);z=vpa(z,n);\u3002
\u5982\uff1a\u89e3\u4e8c\uff08\u591a\uff09\u5143\u4e8c\uff08\u9ad8\uff09\u6b21\u65b9\u7a0b\u7ec4\uff1a
x^2+3*y+1=0
y^2+4*x+1=0
\u89e3\u6cd5\u5982\u4e0b\uff1a
>>syms x y;
>>[x,y]=solve('x^2+3*y+1=0','y^2+4*x+1=0');
>>x=vpa(x,4);
>>y=vpa(y,4);
\u7ed3\u679c\u662f\uff1a
x =
1.635+3.029*i
1.635-3.029*i
-.283
-2.987
y =
1.834-3.301*i
1.834+3.301*i
-.3600
-3.307\u3002
\u4e8c\u5143\u4e8c\u6b21\u65b9\u7a0b\u7ec4\uff0c\u51714\u4e2a\u5b9e\u6570\u6839\uff1b

\u89e3\u7b54\u5982\u4e0b\uff1a
\u57fa\u672c\u65b9\u6cd5\u662f\uff1asolve(s1,s2,\u2026,sn,v1,v2,\u2026,vn)\uff0c\u5373\u6c42\u8868\u8fbe\u5f0fs1,s2,\u2026,sn\u7ec4\u6210\u7684\u65b9\u7a0b\u7ec4\uff0c\u6c42\u89e3\u53d8\u91cf\u5206\u522bv1,v2,\u2026,vn\u3002
\u5177\u4f53\u4f8b\u5b50\u5982\u4e0b\uff1a
x^2 + x*y + y = 3
x^2 - 4*x + 3 = 0
\u89e3\u6cd5\uff1a
>> [x,y] = solve('x^2 + x*y + y = 3','x^2 - 4*x + 3 = 0')
\u8fd0\u884c\u7ed3\u679c\u4e3a
x =
1 3
y =
1 -3/2

\u5373x\u7b49\u4e8e1\u548c3\uff1by\u7b49\u4e8e1\u548c-1.5

\u6216
>>[x,y] = solve('x^2 + x*y + y = 3','x^2 - 4*x + 3= 0','x','y')
x =
1 3
y =
1 -3/2
\u7ed3\u679c\u4e00\u6837\uff0c\u4e8c\u5143\u4e8c\u65b9\u7a0b\u90fd\u662f4\u4e2a\u5b9e\u6839\u3002

\u901a\u8fc7\u8fd9\u4e09\u4e2a\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa\uff0c\u7528matlab\u89e3\u5404\u7c7b\u65b9\u7a0b\u7ec4\u90fd\u662f\u53ef\u4ee5\u7684\uff0c\u65b9\u6cd5\u4e5f\u6709\u591a\u79cd\uff0c\u53ea\u662f\u7528\u5230\u89e3\u65b9\u7a0b\u7ec4\u7684\u51fd\u6570\uff0c\u6ce8\u610f\u6b63\u786e\u4e66\u5199\u53c2\u6570\u5c31\u53ef\u4ee5\u4e86\uff0c\u975e\u5e38\u65b9\u4fbf\u3002

2\u3001\u53d8\u53c2\u6570\u975e\u7ebf\u6027\u65b9\u7a0b\u7ec4\u7684\u6c42\u89e3
\u5bf9\u4e8e\u6c42\u89e3\u975e\u7ebf\u6027\u65b9\u7a0b\u7ec4\u4e00\u822c\u7528fsolve\u547d\u4ee4\u5c31\u53ef\u4ee5\u4e86\uff0c\u4f46\u662f\u5bf9\u4e8e\u65b9\u7a0b\u7ec4\u4e2d\u67d0\u4e00\u7cfb\u6570\u662f\u53d8\u5316\u7684\uff0c\u8be5\u600e\u4e48\u6c42\u5462\uff1f

%\u5b9a\u4e49\u65b9\u7a0b\u7ec4\u5982\u4e0b\uff0c\u5176\u4e2dk\u4e3a\u53d8\u91cf
function F = myfun(x,k)
H=0.32;
Pc0=0.23;W=0.18;
F=[Pc0+H*(1+1.5*(x(1)/W-1)-0.5*(x(1)/W-1)^3)-x(2);
x(1)-k*sqrt(x(2))];

%\u6c42\u89e3\u8fc7\u7a0b
H=0.32;
Pc0=0.23;W=0.18;
x0 = [2*W; Pc0+2*H]; % \u53d6\u521d\u503c
options = optimset('Display','off');
k=0:0.01:1; % \u53d8\u91cf\u53d6\u503c\u8303\u56f4[0 1]
for i=1:1:length(k)
kk=k(i);
x = fsolve(@(x) myfun(x,kk), x0, options);%\u6c42\u89e3\u975e\u7ebf\u6027\u65b9\u7a0b\u7ec4
x1(i)=x(1);
x2(i)=x(2);
end
plot(k,x1,'-b',k,x2,'-r');
xlabel('k')
legend('x1','x2')

\u53ef\u4ee5\u7528solve\u51fd\u6570\u6c42\u89e3\u3002\uff08\u6ce8\u610f\uff0c\u8be5\u51fd\u6570\u5728\u9ad8\u7248\u672c\u4e2d\u4f7f\u7528\u6709\u4e00\u70b9\u95ee\u9898\uff09
syms y1 y2 h1 h2 l1 l2
syms x1 x2
[x1,x2]=solve(y1+y2*x2-h2*x*2^2-2*h1*x1+(l1+l2)*x2==0,y2+y1*x1-h1*x1^2-2*h2*x2+(l1+l2)*x1==0,x1,x2)
\u4e0a\u8ff0\u4ee3\u7801\u5728matlab2016a\u901a\u8fc7\u3002\u7b54\u6848\u6709\u70b9\u957f\u3002



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')



扩展阅读:matlab求解多元方程组 ... matlab求方程的根fminbnd ... 用matlab解微分方程组 ... matlab求方程的根solve ... matlab solve解方程组 ... maple求解代数方程组 ... matlab jacobi解方程组 ... 用matlab计算方程组 ... 怎么用matlab解多元方程组 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网