Curious
Posts:
2,018
Registered:
12/6/04


Re: Heat capacity equation using a string command
Posted:
Feb 23, 2014 5:22 PM


"Susie B" wrote in message <ledlbf$cqp$1@newscl01ah.mathworks.com>... > effort: > function [Cp]= hcap_LRb(T,g) > %UNTITLED2 Summary of this function goes here > % Detailed explanation goes here > g=char('SO2','SO3','O2','N2'); > > if 'SO2'; > a=38.91; > b=3.904e2; > c=8.540e5; > d=32.40e9; > Cp=a+b*T+c*(T.^2)+d*(T.^4); > > if 'SO3'; > a=48.50; > b=9.188e2; > c=8.540e5; > d=32.40e9; > Cp=a+b*T+c*(T.^2)+d*(T.^4); > > if 'O2'; > a=29.10; > b=1.158e2; > c=.6076e5; > d=1.311e9; > Cp=a+b*T+c*(T.^2)+d*(T.^4); > > if 'N2'; > a=29.00; > .2199e2; > c=.5723e5; > d=2.871e9; > Cp=a+b*T+c*(T.^2)+d*(T.^4); > > > end > end > end > end > while 20<=T<=300 > T=[10,20,50,250,400]; > disp('The heat capacity for g is Cp in J.(g*mole*deg C)') > if T<20T>300; > Cp=disp('Temperature entered is outside the range. Temp must be between 20 and 300 deg C.'); > end > end > end > > problem: I only receive one set of answers, it is for N2. > The problem says to display in the Command Window the function output for SO3 and N2 at the following temperatures of 10 deg C, 20 deg C, 50 deg C, 250 deg C, and 400 deg C. However, why do I need the info for SO2 and O2 if I only need So3 and N2 as my outputs?
OK, you gave it a try. So here are some hints:
If g is an input to your function, you shouldn't need to "redefine" it inside the function. I suggest you call your function with g equal to EITHER 'SO2', 'SO3' ,'O2', or 'N2'.
then change your if statements to something like: if isequal(g,'SO2') if isequal(g,'SO3') ...etc.
Before your while statement, insert the line: Cp
Remove or commentout your while loop. It doesn't make much sense.
Now, to solve the problem above call your function once with T=[10,20,50,250,400] & g = 'SO3' and then again with T=[10,20,50,250,400] & g = 'N2' and see what happens.
Then think about how to add error checking and display the results properly.

