Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: FZERO with Inline or Function Handle HELP
Posted:
Sep 25, 2013 8:27 AM


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.8717e2; %kJ/kmole > a3 = 5.2719e5; %kJ/kmole > a4 = 2.1644e8; %kJ/kmole > a5 = 4.5346e12; %kJ/kmole > a6 = 3.7873e16; %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^(gam11); > t2 = @(T2) (T2*V2^(gam21))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^(gam11); foo = T2*V2^(gam21))RS; end
Then you can call answer = fzero(@mycalc,450)
Alan Weiss MATLAB mathematical toolbox documentation



