MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Kyle
on 12 Feb 2013

Hey,

I have to plot two curves to find the critical mach number in matlab. Very rusty at Matlab (been a few years). For the first curve I have to plot the Critical Pressure coefficient value vs. the Critical Mach number and the other curve is the Pressure coefficient (calculated with the minimum pressure coefficient at low speed) vs object mach number

my code thus far is:

Cpo = -0.65; Mcr = linspace(1,8,20); Minfin = linspace(0,1,20);

Ccrit = (2/(1.4*Mcr.^2))*(((((2+(.4*Mcr.^2))/2.4))^3.5)-1); Cp = Cpo/(sqrt(1-Minfin.^2));

plot(Mcr,Ccrit) plot(Minfin,Cp) grid

and I keep getting an error in the Ccrit and Cp lines. Any help is appreciated thanks

*No products are associated with this question.*

Answer by Teja Muppirala
on 12 Feb 2013

You probably just need to change "/" to "./"

Remember, the dot indicates elementwise operations.

This works:

1./[1 2 3]

This does not:

1/[1 2 3]

Answer by Youssef KHMOU
on 12 Feb 2013

hi Kyle : try this :

Cpo = -0.65; Mcr = linspace(1,8,20); Minfin = linspace(0,1,20);

Ccrit = (2./(1.4*Mcr.^2)).*(((((2+(.4*Mcr.^2))./2.4)).^3.5)-1); %keyboard, Cp = Cpo./(sqrt(1-Minfin.^2));

figure, plot(Mcr,Ccrit),xlabel('Critical Mach number'), ylabel('Critical Pressure coefficient value') figure,grid plot(Minfin,Cp,'r'), xlabel('object mach number'), ylabel(' Pressure coefficient' );grid

Youssef KHMOU
on 12 Feb 2013

The erro exist only in power operator "^" you have to use element-wise ".^" .

## 7 Comments

## Brian B

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/63117#comment_128851

What does the error tell you?

## Kyle

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/63117#comment_128852

error using /

## Brian B

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/63117#comment_128853

Did you try breaking down your equations until you found which division produces the error?

## Kyle

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/63117#comment_128855

I took out the *(((((2+(.4*Mcr.^2))/2.4))^3.5)-1); section and still gave me an error on Ccrit. I apologize if it is an elementary error, just rusty at Matlab

## Brian B

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/63117#comment_128859

No worries. But there's nothing like a little debugging to refresh the memory. I'm not trying to be annoying; this is how I learned MATLAB, too. (And I'm doing my own homework right now, as well.)

In the error

you'll notice that the slash is bold and underlined. Click on it. Compare with the function rdivide.

## Kyle

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/63117#comment_128865

Sorry but still don't completely understand where the error is completely

## Brian B

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/63117#comment_129118

You've probably figured it out by now, but you need to change use

You will need to make a similar change to the equation for Cp.