怎么用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
这里每行一个解.
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
这里每行一个解.
追答
那就把x0=solve(A*x^3+B*x^2+C*x+D,x)这一行挪到最后, 不要subs(x)那一行了. 反正只是求最终解.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |