Complex results when using my annonymous function

조회 수: 6 (최근 30일)
Michael Käufl
Michael Käufl 2020년 1월 27일
댓글: Star Strider 2020년 1월 27일
Hey Guys,
I am using runge-kutta-method to integrate function 1, after that i integrate function 2. But I always get complex results for function 2 (except the first iteration). Can anybody tell my why it is how it is? All other variables make sense, so the error should be anywhere else.
Thank you!!
while betrag > tol
for i=1:integrationsende
T_H2O_vektor(i+1) = T_H2O_vektor(i)+h;
X_sat(i) = 0.622 * p_sat_Antoine(T_H2O_vektor(i))/(p - p_sat_Antoine(T_H2O_vektor(i)));
h_Luft_sat(i) = (cp_Luft + cp_Dampf * X_sat(i)) * (T_H2O_vektor(i))+X_sat(i)*h_verdampfung;
Massenstromverhaeltnis = M_H2O_ein/M_Luft*(1 - M_Luft/M_H2O_ein*(X_2 - X_vektor(i)));
%Funktion 1
f1 = @(T_H2O,h_Luft) cp_H2O * Massenstromverhaeltnis *(1+(X_sat(i)-X_vektor(i))*cp_H2O...
*T_H2O/(h_Luft_sat(i)- h_Luft +((0.865^(2/3)*(((0.622+X_sat(i))/...
(0.622+X_vektor(i))-1)/(log((0.622+X_sat(i))/(0.622 + ...
X_vektor(i))))))-1) *(h_Luft_sat(i)- h_Luft-(X_sat(i)-...
X_vektor(i))*(h_verdampfung +cp_Dampf*T_H2O)) - (X_sat(i) ...
- X_vektor(i))*cp_H2O*T_H2O));
l1 = f1((T_H2O_vektor(i) ),(h_Luft_vektor(i) ));
l2 = f1((T_H2O_vektor(i) + 0.5*h),(h_Luft_vektor(i) + 0.5*h*l1));
l3 = f1((T_H2O_vektor(i) + 0.5*h),(h_Luft_vektor(i) + 0.5*h*l2));
l4 = f1((T_H2O_vektor(i) + h),(h_Luft_vektor(i) + h*l3));
h_Luft_vektor(i+1) = h_Luft_vektor(i) + h/6*(l1+2*l2+2*l3+l4);
%Funktion 2
f2 = @(T_H2O,X) cp_H2O * Massenstromverhaeltnis * ((X_sat(i) - X)/(h_Luft_sat(i)...
- h_Luft_vektor(i) + ((0.865^(2/3)*(((0.622+X_sat(i))/(0.622+X)-1)/...
(log((0.622+X_sat(i))/(0.622+X)))))-1)*(h_Luft_sat(i) - ...
h_Luft_vektor(i) -(X_sat(i) - X)*(h_verdampfung + cp_Dampf*T_H2O))) ...
- (X_sat(i) - X)*cp_H2O * T_H2O);
k1 = f2((T_H2O_vektor(i) ),(X_vektor(i) ));
k2 = f2((T_H2O_vektor(i) + 0.5*h),(X_vektor(i) + 0.5*h*k1));
k3 = f2((T_H2O_vektor(i) + 0.5*h),(X_vektor(i) + 0.5*h*k2));
k4 = f2((T_H2O_vektor(i) + h),(X_vektor(i) + h*k3));
X_vektor(i+1) = X_vektor(i) + h/6*(k1+2*k2+2*k3+k4);
X_2R = X_vektor(i) + h/6*(k1+2*k2+2*k3+k4);
betrag = abs(X_2R - X_2);
end
  댓글 수: 1
Star Strider
Star Strider 2020년 1월 27일
Is the argument to the log function here:
log((0.622+X_sat(i))/(0.622+X))
ever negative?
That is the only part of ‘f2’ I can see that could produce a complex result.

댓글을 달려면 로그인하십시오.

답변 (1개)

Michael Käufl
Michael Käufl 2020년 1월 27일
Your answer didn't solve the problem, but I found my problem because I had a look at the part you were talking of. It was a stupid parenthesis error. Thanks!

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by