Please Help - How do I solve this for M

1 次查看(过去 30 天)
I am a bit new to Matlab, I have to solve the following equation for M,
A/B=(1/M)*((2/(G+1)*(1+((G-1)/2)*M^2)))^((G+1)/(2*(G-1)))
Here all the other variables than M (i.e. A, B and G) are known. I need to find the value of M. I tried out with the below code, but it did not work.
eqn=A/B-(1/M)*((2/(G+1)*(1+((G-1)/2)*M^2)))^((G+1)/(2*(G-1)))==0;
solx=solve(eqn,M)
The output came as:
solx =
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 1)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 2)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 3)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 4)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 5)
root(z^6 + 15*z^4 + 75*z^2 - 432*z + 125, z, 6)
The correct output should be a number. Can anyone please help me in this.
Thanks in advance!

回答(1 个)

John D'Errico
John D'Errico 2021-3-21
You need to understand that solve is a solver that will produce an analytical solution if possible. And this apparently reduces to something equivalent to a 6th degree polynomial, so there are 6 roots described. The problem is you cannot solve for a general 6th degree polynomial with the roots in an algebraic form.
What you can do is use vpa to tell MATLAB to reduce the problem to a numerical one. Try
vpa(solx)
  2 个评论
Saumya Nagar 17BME0447
编辑:Saumya Nagar 17BME0447 2021-3-21
Hi John,
Thank you for your help. It now shows the below error. Can you please help me to resolve it. Thanks!
Error using digits (line 42)
The input must be a positive integer larger than 1 and smaller than 2^29 + 1.
Error in sym/vpa (line 30)
digits(d);
Error in first (line 20)
solx=vpa(solx,M)
The entire code is:
clc;
clear all;
format short;
syms M;
G = input('Enter the value of Gamma of the gas used (for monoatomic=1.66, for diatomic=1.4) : ' );
Molecular_Weight=input('Enter the molecular weight of the gas used in grams/mole (for air=28.97): ' );
Stagnation_Temperature = input('Enter the value of Stagnation Temperature in Kelvins : ' );
Mass_Flow_Rate= input('Enter the mass flow rate: ' );
Exit_Area= input('Enter the exit area: ' );
R=8314.46261815324/Molecular_Weight
Throat_Temperature=(2*Stagnation_Temperature)/(G+1)
Throat_Velocity=sqrt(G*R*Throat_Temperature)
Throat_Area=1;
Throat_Density=Mass_Flow_Rate/(Throat_Velocity*Throat_Area)
Throat_Pressure=Throat_Density*R*Throat_Temperature
Stagnation_Pressure=Throat_Pressure*((G+1)/2)^(G/(G-1))
solx=Exit_Area/Throat_Area-(1/M)*((2/(G+1)*(1+((G-1)/2)*M^2)))^((G+1)/(2*(G-1)))==0;
%solx=solve(eqn,M)
solx=vpa(solx,M)
John D'Errico
John D'Errico 2021-3-21
编辑:John D'Errico 2021-3-21
Thats funny. Did I essentially tell you to write this:
solx=vpa(solx,M)
Or, this?
solx=vpa(solx)
I could swear it was the latter. In fact, when I look at my answer, that is clearly what I said. But I could be wrong.
Note that in your code, you did not even use solve. This solves for nothing:
solx=Exit_Area/Throat_Area-(1/M)*((2/(G+1)*(1+((G-1)/2)*M^2)))^((G+1)/(2*(G-1)))==0;
vpa is not solver. It merely reduces the result to a numerical form. solve and vpasolve are solvers. So you MIGHT do:
solx = solve(eqn,M);
solx = vpa(solx);
OR you might do this:
solx = vpa(solve(eqn,M));
OR you might do this:
solx = vpasolve(eqn,M);
The latter works because vpasolve is a numerical solver, so you need not apply vpa to the result.
Go slowly. Look at what you type. It will even help if you read the help for what you use. The odds will now become stronger that you get valid results.

请先登录,再进行评论。

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by