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

18 次查看(过去 30 天)
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
Dana 2020-6-24
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.
In your case, the code:
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
AKARSH KUMAR 2020-6-24

James Tursa
James Tursa 2020-6-24
编辑:James Tursa 2020-6-24
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])

Bjorn Gustavsson
Bjorn Gustavsson 2020-6-24
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

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by