tags:

views:

53

answers:

1

The following equation is to be solved for M by MATLAB:

(Atemp/At)^2=1/M^2*((2/(gamma+1))*(1+(gamma-1)*M^2/2))^((gamma+1)/(gamma-1))

It is not possible to solve this equation symbolically. In Maple it is easily possible to solve such an equation implicitly; now, is there also a pre-made function in Matlab that does this for me? I could program one myself, but as my skills are limited, its performance would not fit my needs.

+2  A: 

I would try using fzero, or if that encounters problems because of complex values/infinities, fminbnd.

Matt Mizumi
Not to be confused with F-Zero. :) http://en.wikipedia.org/wiki/F-Zero_(video_game)
Doresoom
Thanks for posting this, however, this function only gives the roots of the equation and not a numerical solution for M.Awesome game by the way :). Played the SNES version a LOT!
Ingo
@Ingo: Both fzero and fminbnd are numerical solvers. I'm not sure if I understand your objection -- you can trivially rewrite the equation to have a zero on the right side, yes?
Matt Mizumi
Matt is right -- all you have to do is `f = @(M) (Atemp/At)^2 -1/M^2*((2/(gamma+1))*(1+(gamma-1)*M^2/2))^((gamma+1)/(gamma-1)))` and `fzero(f,M0)` where `M0` is an initial guess, or `fminbnd` if required. If you need a symbolic solution, you'll need the MATLAB symbolic toolbox, in which case, it's a simple matter of just using the `solve()` command.
Gilead
In fact, if `Atemp`, `At` and `gamma` are constants (which they are if you're solving for `M`), you can do a little bit of algebra to reduce your equation to `log(M) = C1 + C2*log(2 + C3*M^2)`, where C1, C2, and C3 are constants. Then you can use `fminbnd` and restrict `M` to be greater than some nonzero number, say 1e-6, to avoid 0 in the log term.
Gilead
Thank you so much. I feel totally stupid right now. Figured the same out yesterday night with too much coffee after a too long time and forgot to post that before going to bed. You're right, so thanks again!
Ingo

related questions