Quantcast
Channel: MATLAB Central Newsreader - tag:"homework"
Viewing all articles
Browse latest Browse all 36

Re: Heat capacity equation using a string command

$
0
0

"someone" <someone@somewhere.net> wrote in message
news:ledsak$s2r$1@newscl01ah.mathworks.com...
> "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.904e-2;
>> c=-8.540e-5;
>> d=32.40e-9;
>> Cp=a+b*T+c*(T.^2)+d*(T.^4);
>>
>> if 'SO3';
>> a=48.50;
>> b=9.188e-2;
>> c=-8.540e-5;
>> d=32.40e-9;
>> Cp=a+b*T+c*(T.^2)+d*(T.^4);
>> if 'O2';
>> a=29.10;
>> b=1.158e-2;
>> c=-.6076e-5;
>> d=1.311e-9;
>> Cp=a+b*T+c*(T.^2)+d*(T.^4);
>>
>> if 'N2';
>> a=29.00;
>> .2199e-2;
>> c=.5723e-5;
>> d=-2.871e-9;
>> Cp=a+b*T+c*(T.^2)+d*(T.^4);
>>
>>
>> end
>> end
>> end
>> end
>> while 20<=T<=300

This isn't doing what you think it's doing. See message 2 in this thread:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/334130

>> T=[10,20,50,250,400];
>> disp('The heat capacity for g is Cp in J.(g*mole*deg C)')
>> if T<20||T>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.

Either a block of IF statements or a SWITCH/CASE statement will work.

if isequal(g, 'SO2')
    % Define parameters for SO2
elseif isequal(g, 'SO3')
    % etc.
end

switch g
    case 'SO2'
        % Define parameters for SO2
    case 'SO3'
        % etc
end

When there's a small list of values that need to be processed, I think the
SWITCH/CASE statement makes it clearer that we're doing something different
based on the particular value we receive. But that's mainly personal
preference.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Viewing all articles
Browse latest Browse all 36

Trending Articles