matlab怎么计算方程组
3个回答
展开全部
1、对于比较简单的方程组,可以用solve()函数命令求解。如方程组 x + y = 1 ; x - 11y = 5
>>[x,y]=solve('x + y = 1','x - 11*y = 5')
又如方程组 exp(x+1)-y²=10 ;ln(x)+3y=7
>>syms x y
>>[x,y]=solve(exp(x+1)-y^2-10,log(x)+3*y-7,'x','y')
2、对于比较复杂的方程组,可以用数值方法中的牛顿迭代法,二分法来求解。如方程组
求解代码
x0=[1.0 1.0 1.0]';
tol = 1.0e-6;
x = x0 - newton_dfun(x0)\newton_fun(x0); %newton_dfun导函数,newton_fun函数
n = 1;
while (norm(x-x0)>tol) && (n<1000)
x0 = x;
x = x0 - newton_dfun(x0)\newton_fun(x0);
n = n + 1;
end
x
求解结果为
x = 0.69829;y = 0.62852;z= 0.34256
展开全部
matlab中解方程组还是很方便的,例如,对于代数方程组Ax=b(A为系数矩阵,非奇异)的求解,MATLAB中有两种方法:
(1)x=inv(A)*b — 采用求逆运算解方程组;
(2)x=A\B — 采用左除运算解方程组
PS:使用左除的运算效率要比求逆矩阵的效率高很多~
例:
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;
即二元一次方程组的解x1和x2分别是2和3。
对于同学问到的用matlab解多次的方程组,有符号解法,方法是:先解出符号解,然后用vpa(F,n)求出n位有效数字的数值解.具体步骤如下:
(1)x=inv(A)*b — 采用求逆运算解方程组;
(2)x=A\B — 采用左除运算解方程组
PS:使用左除的运算效率要比求逆矩阵的效率高很多~
例:
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;
即二元一次方程组的解x1和x2分别是2和3。
对于同学问到的用matlab解多次的方程组,有符号解法,方法是:先解出符号解,然后用vpa(F,n)求出n位有效数字的数值解.具体步骤如下:
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
syms x1 x2 x3 x4 x5 f1 f2 f3 f4 f5
f1=(x1+x2+x3+x4+x5+22.55*x1*x4+7.63*x3*x4+148.222*x1^3*x4+5.86*10^13*x1^12*x4^7+67.03*x1*x4^2+212.17*x1*x4^6+338.08*x1*x5+4948932.908*x1^3*x5^2+3522485477*x1^4*x5^3+3.46*x4*x5+4.109*x3*x5+6.03*x3*x5^2+4.847*x3^2*x5+135498.74*x1^3*x2*x4^3+7.55*10^14*x1^11*x2*x4^7)-1;
f2=0.5653*(1/3*x2+135498.74*x1^3*x2*x4^3+7.55*10^14*x1^11*x2*x4^7)-0.2946*(0.5*x1+22.55*x1*x4+444.666*x1^3*x4+7.03*10^14*x1^12*x4^7+67.03*x1*x4^2+212.17*x1*x4^6+338.08*x1*x5+14846798.72*x1^3*x5^2+1.41*10^10*x1^4*x5^3+406496.24*x1^3*x2*x4^3+8.305*10^15*x1^11*x2*x4^7);
f3=0.2946*(0.5*x3+7.63*x3*x4+4.109*x3*x5+6.03*x3*x5^2+9.694*x3^2*x5)-0.05*(1/3*x2+135498.74*x1^3*x2*x4^3+7.55*10^14*x1^11*x2*x4^7);
f4=0.05*(x4+22.55*x1*x4+7.63*x3*x4+148.222*x1^3*x4+4.102*10^14*x1^12*x4^7+134.06*x1*x4^2+1273.02*x1*x4^6+3.46*x4*x5+406496.24*x1^3*x2*x4^3+5.285*10^15*x1^11*x2*x4^7)-0.3456*(0.5*x3+7.63*x3*x4+4.109*x3*x5+6.03*x3*x5^2+9.694*x3^2*x5);
f5=0.3456*(x5+338.08*x1*x5+9897865.816*x1^3*x5^2+1.056*10^10*x1^4*x5^3+3.46*x4*x5+4.109*x3*x5+12.06*x3*x5^2+4.847*x3^2*x5)-0.05*(x4+22.55*x1*x4+7.63*x3*x4+148.222*x1^3*x4+4.102*10^14*x1^12*x4^7+134.06*x1*x4^2+1273.02*x1*x4^6+3.46*x4*x5+406496.24*x1^3*x2*x4^3+5.285*10^15*x1^11*x2*x4^7);
[solx1 solx2 solx3 solx4 solx5]=solve(f1==0,f2==0,f3==0,f4==0,f5==0,x1,x2,x3,x4,x5);
f1=(x1+x2+x3+x4+x5+22.55*x1*x4+7.63*x3*x4+148.222*x1^3*x4+5.86*10^13*x1^12*x4^7+67.03*x1*x4^2+212.17*x1*x4^6+338.08*x1*x5+4948932.908*x1^3*x5^2+3522485477*x1^4*x5^3+3.46*x4*x5+4.109*x3*x5+6.03*x3*x5^2+4.847*x3^2*x5+135498.74*x1^3*x2*x4^3+7.55*10^14*x1^11*x2*x4^7)-1;
f2=0.5653*(1/3*x2+135498.74*x1^3*x2*x4^3+7.55*10^14*x1^11*x2*x4^7)-0.2946*(0.5*x1+22.55*x1*x4+444.666*x1^3*x4+7.03*10^14*x1^12*x4^7+67.03*x1*x4^2+212.17*x1*x4^6+338.08*x1*x5+14846798.72*x1^3*x5^2+1.41*10^10*x1^4*x5^3+406496.24*x1^3*x2*x4^3+8.305*10^15*x1^11*x2*x4^7);
f3=0.2946*(0.5*x3+7.63*x3*x4+4.109*x3*x5+6.03*x3*x5^2+9.694*x3^2*x5)-0.05*(1/3*x2+135498.74*x1^3*x2*x4^3+7.55*10^14*x1^11*x2*x4^7);
f4=0.05*(x4+22.55*x1*x4+7.63*x3*x4+148.222*x1^3*x4+4.102*10^14*x1^12*x4^7+134.06*x1*x4^2+1273.02*x1*x4^6+3.46*x4*x5+406496.24*x1^3*x2*x4^3+5.285*10^15*x1^11*x2*x4^7)-0.3456*(0.5*x3+7.63*x3*x4+4.109*x3*x5+6.03*x3*x5^2+9.694*x3^2*x5);
f5=0.3456*(x5+338.08*x1*x5+9897865.816*x1^3*x5^2+1.056*10^10*x1^4*x5^3+3.46*x4*x5+4.109*x3*x5+12.06*x3*x5^2+4.847*x3^2*x5)-0.05*(x4+22.55*x1*x4+7.63*x3*x4+148.222*x1^3*x4+4.102*10^14*x1^12*x4^7+134.06*x1*x4^2+1273.02*x1*x4^6+3.46*x4*x5+406496.24*x1^3*x2*x4^3+5.285*10^15*x1^11*x2*x4^7);
[solx1 solx2 solx3 solx4 solx5]=solve(f1==0,f2==0,f3==0,f4==0,f5==0,x1,x2,x3,x4,x5);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询