Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

Topic: FZERO with Inline or Function Handle HELP
Replies: 1   Last Post: Sep 25, 2013 8:27 AM

Advanced Search

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

Posts: 1,206
Registered: 11/27/08
Re: FZERO with Inline or Function Handle HELP
Posted: Sep 25, 2013 8:27 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 9/24/2013 7:53 PM, John wrote:
> Hello all,
>
> I am in need of help on how to arrange my equation to find the final
> temperature in a thermodynamics problem. Take a look at what I have
> (mostly constants), and where I am getting the error out. Obviously,
> my problem is in the final lines and how to declare T2 within a
> function to be evaluated by FZERO.
>
> Thanks,
>
> T1 = 350; %kelvin
> V1 = 0.75; %cubic meters
> V2 = V1/50; %cubic meters
> R = 8.314; %kJ/kmole
> a1 = 2.0909e+1; %kJ/kmole
> a2 = 6.8717e-2; %kJ/kmole
> a3 = -5.2719e-5; %kJ/kmole
> a4 = 2.1644e-8; %kJ/kmole
> a5 = -4.5346e-12; %kJ/kmole
> a6 = 3.7873e-16; %kJ/kmole
> global T2;
>
> Cp1 = a1 + T1*(a2 + T1*(a3 + T1*(a4 + T1*(a5 + T1*a6))));
> gam1 = Cp1 / (Cp1 - R);
> Cp2 = a1 + T2*(a2 + T2*(a3 + T2*(a4 + T2*(a5 + T2*a6))));
> gam2 = Cp2 / (Cp2 - R);
> RS = T1*V1^(gam1-1);
> t2 = @(T2) (T2*V2^(gam2-1))-RS;
> T2 = fzero(t2,450)


Your error might not be where you think it is. There are a few problems:
1. Do not make T2 global
2. The line Cp2 = a1 + T2*... does not make sense. T2 is going to be a
free parameter. I think the easiest thing to do is to write a function
such as

function foo = mycalc(T2)
T1 = 350; %kelvin
... % copy everything you have written, now T2 will be passed in when
the function is called
RS = T1*V1^(gam1-1);
foo = T2*V2^(gam2-1))-RS;
end

Then you can call
answer = fzero(@mycalc,450)

Alan Weiss
MATLAB mathematical toolbox documentation





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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.