Verfasst am: 07.01.2010, 13:43
Titel: Probleme mit fzero
Hallo,
Ich habe Probleme mit der fzero funktion im zweiten Teil meines Codes. Ich möchte gerne die Energiebilanz lösen und benutze dazu die folgende Gleichung:
Das geht aber nicht!? Liegt es eventuell an f_eval...(P,T,x), welche selber Funktionen sind die T benötigen? Tf ist eine konstante? Wie könnte ich das schreiben, damit ich T finde wo die gleichung null ergibt?
f_evaldeltaHV(P,Tf,z); %Enthalpy of Feed stream in [J/mol]
f_evaldeltaHV(P,T,y); %Enthalpy of Vapor stream in [J/mol]
f_evaldeltaHL(P,T,x); %Enthalpy of Liquid stream in [J/mol]
%% Init clearall
F=110; %[mol/s] flow rate of gaseous mixture
P=1; % [bar] pressure inside flash unit
Q=-0.55*10^6; % [W] heat duty of flash
z=[0.170.230.30.10.060.14]; % molar fraction of feed (row vector)
T=250; %[K] %initial guess temperature of flash
%1. guess V/F (assumed zeta (split fracton of flash)=1for z1,z2 and z3. Rest zeta=0
V=sum(F*z(1:3)); %Vapor flow in mol/s
L=sum(F*z(4:6)); %Liquid flow in mol/s
VF=V/F; % V/F= alpha (a)
%% ----Solve T,P flash---------------------------------------------------------------------
timax=1000;
for ti=1:timax
[VF, x, y] = IdealFlash(P, T, VF, z)
%3. evaluate K(P, T, x, y) call f_evalK(P,T,x,y)
K=f_evalK(P,T,x,y)
%4. solve
f=inline('sum((K-1).*z./(1+(K-1)*VF))','VF','K','z');
% LOOP1
Kchange=1; %just for having an initially large value (see next, "while", line)
roundmax=1000;
round=1;
while(Kchange>1e-5)
VF=fzero(f,VF,[],K,z);
%5. evaluate x and y
x=z./(1+(K-1)*VF)
y=K.*x
Knew=f_evalK(P,T,x,y)
Kchange=sum(abs(Knew-K));
K=Knew;
ifround==roundmax
disp('ERROR: ''round'' reached ''roundmax'', aborting..');
break;
end;
round=round+1
VF
end
%% Second iteration: Solve the energy balance
V=F*VF; % Vapor stream in mol/s
L=F-V; % Liquid stream in in mol/s
P=1;
Tf=350; %Temperature of feed
% Tchange=1000 % while (abs(Tchange)>1e-5) % HF=f_evaldeltaHV(P,Tf,z); %Enthalpy of Feed stream in [J/mol] % HV=f_evaldeltaHV(P,T,y); %Enthalpy of Vapor stream in [J/mol] % HL=f_evaldeltaHL(P,T,x); %Enthalpy of Liquid stream in [J/mol]
Dazu müssen f_evaldeltaHV etc. Dateien mit jeweils 3 Eingabe- und 1 Rückgabeargument (oder ein entsprechendes Function Handle) sein und alle Variablen außer T (P, Tf, z etc.) vorher im Workspace definiert werden. Alternativ können sie auch direkt in der Code geschrieben werden, z.B.
Vielen Dank, hat nun geklappt. Ich bin wirklich sehr sehr froh über Deine Hilfe.
Wobei, ich habe auch schon gesehen, dass folgende Kombination verwendet wurde:
Code:
function zero = energy_Balance(R,Q,Feed,z,alpha,T1,Hf,A,B,C,D,E,F); %dieser Teil ist in einem separation m file als funktion definiert, deshalb das "function" vor dem "zero". Es handelt sich hier nur um einen Ausschnitt.
R = fzero(@energy_balance_BP, R0, [],Q,Fe,z,alpha,T1,Hf,A,B,C,D,E,F);
und das klappt (Allerdings eine andere Methode, die keine direkte Enthalpy Berechnung macht, sonder nur indirekt über R, ABC...). Ich habe allerdings nie ganz verstanden für was das "@" steht und []. Ich nehme an [] trennt die "normalen Inputs" von der Zielvariable.
Danke Harald. Wenn auch die Erklärung im Matlab Help für Function Handle nicht gerade bezaubernd ist, fand ich einen Eintrag hier im Forum, welcher einiges klarer ist.
Zum Beispiel:
HANDLE Superclass of all handle classes.
A handle is an object that indirectly references its data. When a
handle is constructed, an object with storage for property values is
created. The constructor returns a handle to this object. When a
handle object is copied, for example during assignment or when passed
to a MATLAB function, the handle is copied but not the underlying
object property values.
The HANDLE class is an abstract class and cannot be directly
constructed. It is the superclass for all classes that follow handle
semantics.
Schon ziemlich kauderwelsch...obwohl ich Englisch praktisch flüssig spreche...
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.