How to find the intersection points on two functions

조회 수: 5 (최근 30일)
sophp
sophp 2018년 2월 4일
댓글: Walter Roberson 2018년 2월 4일
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에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by