# How could I use MATLAB to solve for x with this equation, 0=a*x^(3)+b*x^(-1)+c.

조회 수: 7(최근 30일)
Matthew Speijer 24 Jun 2020
답변: Dana 24 Jun 2020
This is my actual equation:
58.8*(550)=0.5*37*0.002377*x^3*(0.02+0.062((2*960)/(0.002377*37*x^2))^2)
The real values are 40.2498, 317.889
I've already tried fzero to no avail.
Thanks

### 채택된 답변

Dana 24 Jun 2020
A few things:
First, you're missing a * between 0.062 and the ( that follows it.
Second, I have no trouble solving this equation with fzero. You say you tried fzero but it didn't work. Can you post your code?
Third, fzero is actually not the best way to go about finding all of the multiple solutions to an equation, since it only looks for a sinlge solution and stops as soon as it does. Luckily, your equation can be converted to a polynomial form very easily: multiply both sides by x to get , which is a quartic equation in x, the solutions of which can be found in MATLAB via the roots function: roots([a,0,0,c,b]) will give you the answers.
g = 0.5*37*0.002377;
h = ((2*960)/(0.002377*37))^2;
a = 0.02*g;
b = 0.062*g*h;
c = -58.8*(550);
rts = roots([a,0,0,c,b])
returns all the solutions (including complex ones):
rts =
1.0e+02 *
-1.7907 + 2.8879i
-1.7907 - 2.8879i
3.1789 + 0.0000i
0.4025 + 0.0000i
Since you're not interested in the complex ones, you can extract the real ones via:
rlrts = rts(imag(rts)==0)
which returns
rlrts =
317.8889
40.2498
as desired.

### 추가 답변(3개)

AKARSH KUMAR 24 Jun 2020

#### 댓글 수: 0

James Tursa 24 Jun 2020
편집: James Tursa 24 Jun 2020
Just use the roots( ) function. If you have a negative integer power of x in the expression such as x^(-n), then multiply everything by x^n first to give yourself a polynomial to work with, then call roots( ).
0=a*x^(3)+b*x^(-1)+c
becomes
0=a*x^(4)+b+c*x
then feed the coefficients to roots( ):
roots([a,0,0,c,b])

#### 댓글 수: 0

Bjorn Gustavsson 24 Jun 2020
This works perfectly fine:
f = @(x ) -58.8*(550) + 0.5*37*0.002377*x.^3.*(0.02+0.062*((2*960)./(0.002377*37*x.^2)).^2);
plot(linspace(0,1000,1001),asinh(f(linspace(0,1000,1001))))
grid on
fzero(f,[100 400])
% 317.89
fzero(f,[10 300])
% 40.25
HTH

R2020a

Translated by