怎么用MATLAB求解一元三次方程?为Ax^3+Bx^2+Cx+D=0这种模式的?

如题所述

在命令窗口中输入:
syms A B C D x
x=solve(A*x^3+B*x^2+C*x+D,x) % 这是求符号解.
A=1;B=2;C=3;D=4; %这是具体的取值, 改成你想要的.
x0=subs(x) %这是A, B, C, D取上边的值以后得到的数值解.

输出三个不同的解:
x = 1/6/A*(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)-2/3*(3*C*A-B^2)/A/(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)-1/3*B/A
-1/12/A*(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)+1/3*(3*C*A-B^2)/A/(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)-1/3*B/A+1/2*i*3^(1/2)*(1/6/A*(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)+2/3*(3*C*A-B^2)/A/(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3))
-1/12/A*(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)+1/3*(3*C*A-B^2)/A/(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)-1/3*B/A-1/2*i*3^(1/2)*(1/6/A*(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3)+2/3*(3*C*A-B^2)/A/(36*C*B*A-108*D*A^2-8*B^3+12*3^(1/2)*(4*C^3*A-C^2*B^2-18*C*B*A*D+27*D^2*A^2+4*D*B^3)^(1/2)*A)^(1/3))

x0 =

-1.6506
-0.1747 + 1.5469i
-0.1747 - 1.5469i
这里每行一个解.追问

我这个A B C D是其他输入量求出的,而且我编的是m文件,想问一下怎么求解呢?

追答

那就把x0=solve(A*x^3+B*x^2+C*x+D,x)这一行挪到最后, 不要subs(x)那一行了. 反正只是求最终解.

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答