The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Heat capacity equation using a string command
Replies: 4   Last Post: Feb 24, 2014 9:59 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 2,359
Registered: 12/6/04
Re: Heat capacity equation using a string command
Posted: Feb 23, 2014 5:22 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Susie B" wrote in message <ledlbf$cqp$>...
> 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
> 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')

Before your while statement, insert the line:

Remove or comment-out 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.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.