MATLAB: Trying to plot a function but only one value is appearing

linspaceplotplottingsimplevaluevectorvectors

I'm just trying to plot this function:
gamma = 1.40;
M1 = linspace(1.00,10.0,1000);
M2 = ((1 + (gamma-1)/2*M1.^2)/(gamma*M1.^2-(gamma-1)/2)).^(1/2);
plot(M1,M2);
but whenever I run the script, nothing shows up on my graph and the variable M2 is stored as a single value: 0.3938. I've plotted functions like this before no problem. Why isn't M2 being stored as a vector? I tried preallocating M2 as well and nothing changed.

Best Answer

The / operator treats its operands as matrices. If you want an elementwise operation, use ./ :
M2 = sqrt((1 + (gamma-1) / 2 * M1 .^ 2) ./ (gamma * M1 .^ 2 - (gamma - 1) / 2));
Note that sqrt() is more efficient than ^0.5.