Filter löschen
Filter löschen

How to solve a function with symbolic tool

2 Ansichten (letzte 30 Tage)
Davide Bassignana
Davide Bassignana am 13 Apr. 2017
Bearbeitet: Davide Bassignana am 13 Apr. 2017
I want to solve a function with symbolic math toolbox. The equation is quite simple but I can't solve it for the variale I want by hand. It should contain two function handles and one of them contain the variable I want to solve for. Here is the code:
gamma = 1.4;
M0 = 1.5;
PhiD = 0.93;
ed=0.9298;
fM =@ (M) (sqrt(gamma).*M)./(1+0.5*(gamma-1).*M^2)^((gamma+1)/(2*(gamma-1)));
syms M
f = ed*(fM(M)/fM(M0))-PhiD;
Mi=solve(f,M)
Last command returns a 1x1 sym variable and the command window displays : Mi =
root(487667696955747081*5^(1/2)*7^(1/2)*z^6 + 7315015454336206215*5^(1/2)*7^(1/2)*z^4 + 36575077271681031075*5^(1/2)*7^(1/2)*z^2 - 732792583293936200000*z + 60958462119468385125*5^(1/2)*7^(1/2), z, 1)
root(487667696955747081*5^(1/2)*7^(1/2)*z^6 + 7315015454336206215*5^(1/2)*7^(1/2)*z^4 + 36575077271681031075*5^(1/2)*7^(1/2)*z^2 - 732792583293936200000*z + 60958462119468385125*5^(1/2)*7^(1/2), z, 2)
root(487667696955747081*5^(1/2)*7^(1/2)*z^6 + 7315015454336206215*5^(1/2)*7^(1/2)*z^4 + 36575077271681031075*5^(1/2)*7^(1/2)*z^2 - 732792583293936200000*z + 60958462119468385125*5^(1/2)*7^(1/2), z, 3)
root(487667696955747081*5^(1/2)*7^(1/2)*z^6 + 7315015454336206215*5^(1/2)*7^(1/2)*z^4 + 36575077271681031075*5^(1/2)*7^(1/2)*z^2 - 732792583293936200000*z + 60958462119468385125*5^(1/2)*7^(1/2), z, 4)
root(487667696955747081*5^(1/2)*7^(1/2)*z^6 + 7315015454336206215*5^(1/2)*7^(1/2)*z^4 + 36575077271681031075*5^(1/2)*7^(1/2)*z^2 - 732792583293936200000*z + 60958462119468385125*5^(1/2)*7^(1/2), z, 5)
root(487667696955747081*5^(1/2)*7^(1/2)*z^6 + 7315015454336206215*5^(1/2)*7^(1/2)*z^4 + 36575077271681031075*5^(1/2)*7^(1/2)*z^2 - 732792583293936200000*z + 60958462119468385125*5^(1/2)*7^(1/2), z, 6)
But Mi should be a number. How can I fix it ?

Akzeptierte Antwort

KSSV
KSSV am 13 Apr. 2017
class sym can be converted to double using double.
double(Mi)
  1 Kommentar
Davide Bassignana
Davide Bassignana am 13 Apr. 2017
Bearbeitet: Davide Bassignana am 13 Apr. 2017
Edit: it works, there are imaginary solutions but one of them is real ! thaks again !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by