1、符号的解,线性的一般是数字,不是数值的啊,看例子:
syms u v
eqns = [2*u + v == 0, u - v == 1];
[s_u,s_v] = solve(eqns,[u v])
s_u =
1/3
s_v =
-2/3
如果想要变成数值型的,可以用double函数进行转变,看代码:
d_u= double(s_u);
d_v= double(s_v);
d_u =
0.3333
d_v =
-0.6667
2、如果是非线性方程,也可以是数字的,这种一般简单点。
看例子:
syms u v
eqns = [2*u^2 + v^2 == 0, u - v == 1];
vars = [v u];
[solv, solu] = solve(eqns,vars)
solv =
- (2^(1/2)*1i)/3 - 2/3
(2^(1/2)*1i)/3 - 2/3
solu =
1/3 - (2^(1/2)*1i)/3
(2^(1/2)*1i)/3 + 1/3
3、 如果非线性的方程,复杂的,就可能是表达式了,看例子:
syms u v
eqns = [2*u^3 + v^3 == 0, u^2 - v^2 == 1];
vars = [v u];
[solv, solu] = solve(eqns,vars)
solv =
3*root(z^6 + z^4 - z^2 + 1/3, z, 1)^3 + (3*root(z^6 + z^4 - z^2 + 1/3, z, 1)^5)/2 - root(z^6 + z^4 - z^2 + 1/3, z, 1)/2
3*root(z^6 + z^4 - z^2 + 1/3, z, 2)^3 + (3*root(z^6 + z^4 - z^2 + 1/3, z, 2)^5)/2 - root(z^6 + z^4 - z^2 + 1/3, z, 2)/2
3*root(z^6 + z^4 - z^2 + 1/3, z, 3)^3 + (3*root(z^6 + z^4 - z^2 + 1/3, z, 3)^5)/2 - root(z^6 + z^4 - z^2 + 1/3, z, 3)/2
3*root(z^6 + z^4 - z^2 + 1/3, z, 4)^3 + (3*root(z^6 + z^4 - z^2 + 1/3, z, 4)^5)/2 - root(z^6 + z^4 - z^2 + 1/3, z, 4)/2
3*root(z^6 + z^4 - z^2 + 1/3, z, 5)^3 + (3*root(z^6 + z^4 - z^2 + 1/3, z, 5)^5)/2 - root(z^6 + z^4 - z^2 + 1/3, z, 5)/2
3*root(z^6 + z^4 - z^2 + 1/3, z, 6)^3 + (3*root(z^6 + z^4 - z^2 + 1/3, z, 6)^5)/2 - root(z^6 + z^4 - z^2 + 1/3, z, 6)/2
solu =
root(z^6 + z^4 - z^2 + 1/3, z, 1)
root(z^6 + z^4 - z^2 + 1/3, z, 2)
root(z^6 + z^4 - z^2 + 1/3, z, 3)
root(z^6 + z^4 - z^2 + 1/3, z, 4)
root(z^6 + z^4 - z^2 + 1/3, z, 5)
root(z^6 + z^4 - z^2 + 1/3, z, 6)
4、继续上面的例子,这种结果看不懂的话,我们也可以用double进行转变,看代码:
d_solv = double(solv)
d_solu = double(solu)
d_solv =
-0.1637 - 0.8220i
0.1637 - 0.8220i
0.1637 + 0.8220i
-0.1637 + 0.8220i
0.0000 + 1.6439i
0.0000 - 1.6439i
d_solu =
-0.6300 - 0.2136i
0.6300 - 0.2136i
0.6300 + 0.2136i
-0.6300 + 0.2136i
0.0000 - 1.3048i
0.0000 + 1.3048i
5、当然,其实还可以用solve的兄弟vpasolve进行求解,这个还是符号的解,只是数字的显示结果,看代码:
syms u v
eqns = [2*u^3 + v^3 == 0, u^2 - v^2 == 1];
vars = [v u];
[solv, solu] = vpasolve(eqns,vars)
solv =
- 0.16374000103666315499224751599704 - 0.82195109099010800998118393702527i
- 0.16374000103666315499224751599704 + 0.82195109099010800998118393702527i
0.16374000103666315499224751599704 - 0.82195109099010800998118393702527i
0.16374000103666315499224751599704 + 0.82195109099010800998118393702527i
1.6439021819802160199623678740505i
-1.6439021819802160199623678740505i
solu =
- 0.62996052494743658238360530363911 - 0.21364239053238529665579124243869i
- 0.62996052494743658238360530363911 + 0.21364239053238529665579124243869i
0.62996052494743658238360530363911 - 0.21364239053238529665579124243869i
0.62996052494743658238360530363911 + 0.21364239053238529665579124243869i
-1.3047660265041067002158638566285i
1.3047660265041067002158638566285i
6、就这么多了吧。
7、对了,复杂的就不要用solve求解了,可能会出错。