finding variable of a given equation

I want to get the value of b given the equation, where AonAstar = 16 and gamma = 1.22
AonAstar = ((b)^(1/gamma)*(1-(b)^((gamma-1)/gamma))^(1/2))/(((gamma-1)/2)^(1/2)*(2/(gamma+1))^((gamma+1)/(2*(gamma-1))));

 Accepted Answer

Q = @(v) sym(v);
AonAstar = Q(16);
gamma = Q(1.22);
syms b
eqn = AonAstar == ((b)^(1/gamma)*(1-(b)^((gamma-1)/gamma))^(1/2))/(((gamma-1)/2)^(1/2)*(2/(gamma+1))^((gamma+1)/(2*(gamma-1))));
fplot(lhs(eqn) - rhs(eqn), [-2 2])
b_solution = vpasolve(eqn, b)
disp(char(b_solution))
0.88020141415289762313250086000262 + 6.1375868700814434734289784153891i
We can see from the graph that there are no solutions over the reals.

More Answers (1)

gamma is a really bad choice of variable names, since gamma is itself a very useful function in MATLAB. Try to avoid doing these things, because one day soon you will need to use gamma yourself as a function. I've used g instead, to replace gamma.
AonAstar = 16;
g = 1.22;
syms b
I'll subtract the right hand side from AonAstar, to create a problem where we will look for a zero.
eqn = AonAstar - (b^(1/g)*sqrt(1-b^((g-1)/g)))/((sqrt(g-1)/2)*(2/(g+1))^((g+1)/(2*(g-1))))
fplot(eqn,[0,1])
For a solution to exist, this curve must cross zero, and must do so in the interval [0,1], since it is only real valued in that interval.
As you can see, it never even comes close to zero, being always positive.

5 Comments

@Irfan cannot be blamed for assigning the value 1.22 to the variable gamma of his choice. To most engineering students, it is merely a commonly used lowercase symbol, similar to alpha (α), beta (β), and gamma (γ), which are among the first three letters of the Greek alphabet. While the Gamma function, , is important in advanced mathematics, it is less familiar to those with only a basic understanding of undergraduate engineering math.
Technically, the MATLAB function should use the uppercase gamma because the Gamma function is denoted as .
I've given no blame to their choice. Instead, I chose to use this as a teaching moment, since the use of a variable name that overloads a useful function is perhaps one of the most common errors new users make. It is also one of the most difficult errors to see for a new user, until they are taught to watch their choice of variable name a little more carefully.
Should gamma have been named Gamma long ago? You can make that argument if you wish, but it will fall on deaf ears, since lower case gamma goes back 40 years since version 1, when everything was lower case. Tell it to Cleve.
I agree that it was a good opportunity to educate new users, even though they may not use the special function for some time. I suggest that new users explore other special functions at the link below. Coincidentally, the Beta function also uses the lowercase beta (β). I admit that I have also occasionally assigned a value to a variable named 'beta'.
It is a habit we need to train our minds to avoid if we are to use MATLAB successfully. And yes, it is far too easy to name variables alpha, beta, gamma, and yes, I fail at it at times myself. My tendency is to use contractions, like alph, bet, gam, or I might deliberately mispell the greek letter, perhaps as gammuh. Or I'll capitalize the name, using Gamma. At least all of these variations in names remind me of the relation of my code to my thinking.
These are good suggestions and practice. 👍

Sign in to comment.

Categories

Products

Release

R2024a

Asked:

on 19 Oct 2024

Commented:

on 20 Oct 2024

Community Treasure Hunt

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

Start Hunting!