How to find the intersection points on two functions

2 次查看(过去 30 天)
how to find the intersection points of dH_rem and dH_gen within the limits specified below
To=500:1:850; %outlet temp
Ti=570; %inlet temp
y_A=0.003; %proportion of benzene in feed
V=8.5;
P=3e5; %Pa
R=8.3145; %kJ/mol.K
Cp=1.09 %kJ/kgK
Mr_air=29e-3; %kg/mol
dH_1=-1850; %kJ/mol
dH_2=-1423;
dH_3=-3273;
F_ao=0.1; %molar flow rate of benzene
k1 = 1e7.*exp(-12700./To);
k2 = 5e4.*exp(-10800./To);
k3 = 7e7.*exp(-15000./To);
t=(V.*y_A.*P)./(F_ao.*R.*To);
X=(t.*(k1+k3))./(1+t.*(k1+k3));
S=k1./((1+(k2.*t)).*(k1+k3));
Y_B = (k1.*t)./(((k2.*t)+1).*(1+(t.*(k1+k3))));
dH_gen=-((V.*y_A.*P)./(R.*To)).*((((k1.*dH_1)+(k3.*dH_3)).*(1-X))+(k2.*X.*S.*dH_2));
plot(To,dH_gen)
hold on
dH_rem=(Mr_air./y_A).*F_ao.*Cp.*(To-Ti);
plot(To,dH_rem)
hold off

回答(1 个)

John D'Errico
John D'Errico 2018-2-4
Standard question: how to find the intersection(s) of two functions.
1. Subtract them. Where the difference is zero, there lies an intersection.
2. Use a root finder. That could be anything from fzero, solve, vpasolve, fsolve, etc.
Note that all standard optimization based root finders will find ONE root, and only one root. It will depend on your starting values. Solve might be able to find the three points of intersection I saw on the plot.
The lazy solution to finding an approximate root is to use a tool like Doug Schwarz's intersections code on the FEX. Evaluate each function at a few hundred points, then call intersections. It will use linear interpolation to find the crossing points. But a virtue of that solution is it will report all crossings between the curves.
  4 个评论
sophp
sophp 2018-2-4
Thank you!! Okay, so I replaced
To=500:1:850
with
syms To
Matlab then tells me that the equation dH_rem-dH_gen is unsolvable symbolically and gives me a numerical approximation instead.
The solution is correct but how do I alter the code to give the lowest intersection value.
Walter Roberson
Walter Roberson 2018-2-4
When I use the code you posted, except replacing that assignment with syms To, then dH_rem = (3161*To)/3000 - 60059/100 which is linear with the single solution To == 570. Perhaps you are using different code by now?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by