Finding values of a variable as parameters change

I was given an excel file for coordinates of axis and radius in a combustion chamber, throat and nozzle. I am trying to find the mach number,M, while relating E and EM. It is given that E=EM, or E-EM=0. I have all of the variables except M and cannot rearrange EM nicely to find M. Since M changes at each different radius along the axis, I need to output M at each point on the axis. I've tried solve(...), fzero(...) and a few other functions. How can I do this?
%Constants
coordinates='nc.xlsx';
z=xlsread(coordinates,'A:A'); %[cm] axis
y=xlsread(coordinates,'B:B'); %[cm] radius
At=pi*(0.1)^2;%[m] throat area
Ae=pi*(.2240085)^2;%[m] exit area
Pc=7000000; %[Pa] chamber pressure
Pa=101325; %[Pa] Atmosperic Pressure
Tc=3300; %[K] chamber temp
MW=15; %[kg/mol] molecular weight
Y=1.2; %gamma
R=8314/MW; %[J/kg*K]
Ex=Ae/At; %Ae/At
cstar=((Y*R*Tc)^.5)/(Y*(((2/(Y+1))^((Y+1)/(Y-1)))^.5)); %[m/s] c*
mdot=(Pc*At)/cstar; %[kg/s] mass flow rate
%Equations
E=(y.^2)/(At^2); %A/At
i=size(y);
EM=(1/M)*((2+(Y-1)*M^2)/(Y+1))^((Y+1)/(2*(Y-1))); %E in terms of Y and M

3 Comments

@Alex Mastrean: please edit your question and upload the file nc.xlsx. Without it we cannot run your code.
Please also show us how you tried to use solve and fzero.
I added the file. Even a hint would be great. I've been stuck for a couple hours and don't know what a "smart" next move would be. I deleted/edited my code several times, but here is what I can find.
Ma=solve(EM,M); %Mach number
fzero((E=EM),[min(y),max(y)]);
The fzero documentation clearly states that the first input should be a function handle. Where do you define the function handle in your code?

Sign in to comment.

 Accepted Answer

You need to learn about function handles, and how to define them:
>> EM = @(M)(1./M).*((2+(Y-1).*M.^2)/(Y+1)).^((Y+1)/(2*(Y-1)));
And then we can call fzero on the first E value, using the function EM:
>> fzero(@(m)E(1)-EM(m),[min(y),max(y)])
ans =
12.896
And you can use arrayfun to call fzero for each value of E:
>> arrayfun(@(e)fzero(@(m)e-EM(m),[min(y),max(y)]),E)
ans =
12.896
12.896
12.896
12.864
12.77
12.614
11.893
11.617
11.43
11.364
11.371
11.394
11.43
11.553
11.67
11.784
11.893
11.999
12.101
12.201
12.297
12.39
12.481
12.57
12.656
12.74
12.821
12.901
12.979
13.056
13.13
13.203
13.275
13.345
13.414
13.51
Do those values look reasonable to you? Note that if fzero fails to find a solution then this code will throw lots of errors. Good luck!

2 Comments

Hmm, the values should be lower. I know one value somewhere in the middle needs to be 1. However, this helps tremendously! I probably just have a mistake in the code somewhere. Thank you very much!
fzero solves for one value, so you cannot use it to solve for every E value at once. Therefore I simply index into E to get each value in turn: E(1) is its first value. I am not sure where you see E(m) but it is not in my code, does not make any sense, and would result in an error. EM(m) is simply the function EM calculated at the value m (in my code the value of m is determined by fzero). You can also try it yourself:
>> EM(1.5)
ans =
1.205

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!