MATLab does not solve for my variable and only solves the root of the equation

2 次查看(过去 30 天)
Hello, I'm new to MATlab, here is the code and the equation:
syms a H Q x y z b c d e f g h
eqn = x + y*a + z*H + b*a^2 + c*H^2 + d*a^3 + e*H^3 + f*a*H + g*a^2*H + h*a*H^2 == Q;
solutions = solve(eqn, a)
solutions = 
variables x y z b c d e f g and h are all constants but they are long numbers so I decided to write them like this. I would like MATlab to solve for a but it just gives me the root of the equation which is useless to me. I even tried replacing the other variables like Q and H with constant to no avail. Even with the only variable being a MATlab still solves for roots instead for a...
  3 个评论
Primoz
Primoz 2024-6-10
I want an equation that looks something like this: a = b*h + c*h^2...
Because I need to make an excel table where the on the top I have Q and on the left side H and inside the table the a values.
Torsten
Torsten 2024-6-10
编辑:Torsten 2024-6-10
You get three solutions for "a" because you want to solve a polynomial equation of degree 3 in "a":
If you write your equation as
eqn = b1 + b2*a + b3*a^2 + b4*a^3 == 0
with
b1 = x + z*H + c*H^2 + e*H^3 - Q
b2 = y + f*H + h*H^2
b3 = b + g*H
b4 = d
you get the three "a" values as follows (a bit more compact than in @Walter Roberson 's answer):
syms b1 b2 b3 b4 real
syms a
eqn = b1 + b2*a + b3*a^2 + b4*a^3 == 0;
asol = solve(eqn,a,'MaxDegree',3)
asol = 

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2024-6-10
syms a H Q x y z b c d e f g h
eqn = x + y*a + z*H + b*a^2 + c*H^2 + d*a^3 + e*H^3 + f*a*H + g*a^2*H + h*a*H^2 == Q;
solutions = solve(eqn, a, 'maxdegree', 3)
solutions = 

Community Treasure Hunt

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

Start Hunting!

Translated by