Is it possible to use the bisection method?

2 views (last 30 days)
Aaron on 7 Apr 2014
Edited: Aaron on 7 Apr 2014
I'm having a difficult time setting up my code.
Here is a quick rundown of what I'm trying to do: I have a set(4) of equations (we'll call them setA) that rely on a temperature, T. I also have another set (5) of equations (we'll call them setB) that also rely on T and phi (0.2:0.2:1.0).
I figured I could eliminate having to write a loop using the phi values and just put them in each of the setB equations. Below are the equations that I wrote:
hO2 = 1.507*(T-298) - 33.54*(sqrt(T)-sqrt(298)) + 111.1*log(T/298);
hN2 = 1.450*(T-298) - 287.9*log(T/298) + (5.35e4)*((1/298)-(1/T));
hCO2 = 1.540*(T-298) - 245.1*log(T/298) + (4.13e4)*((1/298)-(1/T));
hH2O = 4.613*(T-298) - 206.6*(sqrt(T)-sqrt(298)) + 967.5*log(T/298);
HR=-249400;
HP1= -6595306+11*(hH2O)+10*(hCO2)+62.00*(hO2)+294.1*(hN2); % phi=0.2
HP2= -6595306+11*(hH2O)+10*(hCO2)+23.25*(hO2)+145.7*(hN2); % phi=0.4
HP3= -6595306+11*(hH2O)+10*(hCO2)+10.33*(hO2)+97.13*(hN2); % phi=0.6
HP4= -6595306+11*(hH2O)+10*(hCO2)+3.875*(hO2)+72.85*(hN2); % phi=0.8
HP5= -6595306+11*(hH2O)+10*(hCO2)+0.000*(hO2)+58.28*(hN2); % phi=1.0
Now I wanted to use the bisect method to make the following statement true:
HR-HP=0
And I wanted to go through a range of 300:50000 values of T, to check this statement. Would I have to create a script for each of setB equations and bisect them individually? Or can I run one bisect program to find the temperature for each setB equation?
Thank you!

John D'Errico on 7 Apr 2014
Thinking clearly about a problem, stating it clearly enough is often the very first step to solving it.
So, you have 4 equations, relating the parameters hO2, hN2, hCO2, hH2O, each to the parameter T.
Then, as a function of phi and the 4 computed parameters above, you have 5 other relations, EACH of which you wish to satisfy simultaneously.
So essentially you have 5 simultaneous equations in one unknown, T. And you wish to find a value of T that will satisfy all 5 of them at once. Without even looking at this more carefully, I'll claim that no single value of T will suffice.
So lets create a few function handles.
hO2 = @(T) 1.507*(T-298) - 33.54*(sqrt(T)-sqrt(298)) + 111.1*log(T/298);
hN2 = @(T) 1.450*(T-298) - 287.9*log(T/298) + (5.35e4)*((1/298)-(1./T));
hCO2 = @(T) 1.540*(T-298) - 245.1*log(T/298) + (4.13e4)*((1/298)-(1./T));
hH2O = @(T) 4.613*(T-298) - 206.6*(sqrt(T)-sqrt(298)) + 967.5*log(T/298);
Note that I used ./ in here where necessary to vectorize these equations for a vector of values of T.
We now have 4 functions of the variable T. Next, build the set of 5 equations you wish to solve.
HR = -249400;
HP1 = @(T) -6595306+11*hH2O(T)+10*hCO2(T)+62.00*hO2(T)+294.1*hN2(T);
HP2 = @(T) -6595306+11*hH2O(T)+10*hCO2(T)+23.25*hO2(T)+145.7*hN2(T);
HP3 = @(T) -6595306+11*hH2O(T)+10*hCO2(T)+10.33*hO2(T)+97.13*hN2(T);
HP4 = @(T) -6595306+11*hH2O(T)+10*hCO2(T)+3.875*hO2(T)+72.85*hN2(T);
HP5 = @(T) -6595306+11*hH2O(T)+10*hCO2(T)+0.000*hO2(T)+58.28*hN2(T);
HP = @(T) [HP1(T),HP2(T),HP3(T),HP4(T),HP5(T)];
Now, form HR - HP, and see what happens for various values of T. We can plot the result, looking at each equation as a separate curve in the plot.
T = (300:50000)';
plot(T,HR - HP(T))
grid on
xlabel T
ylabel 'HR - HP(T)' There are 5 curves plotted in distinct colors there, one curve for each value of phi. Where the curve crosses zero is the value of T for which you search.
Clearly no SINGLE value of T satisfies them all. However, you could use fzero to solve for a distinct value of T for EACH curve.
fzero(@(T) HR - HP1(T),[300,50000])
ans =
12168
fzero(@(T) HR - HP2(T),[300,50000])
ans =
22240
fzero(@(T) HR - HP3(T),[300,50000])
ans =
30986
fzero(@(T) HR - HP4(T),[300,50000])
ans =
38712
fzero(@(T) HR - HP5(T),[300,50000])
ans =
45591
See that I never needed bisection in any of this, simply used the tools in MATLAB. Once you learn those tools, and ONCE you decide what problem you want to solve, problems are simple to solve.
Aaron on 7 Apr 2014
John, I understand what you did and I used the bisection method and got the same answers. But apparently my equations are wrong, therefore my answers are wrong. The initial one is supposed to be around 850. Thank you for your help anyway.