Results 1 to 4 of 4

Math Help - Matlab fzero function

  1. #1
    Newbie
    Joined
    Jan 2010
    Posts
    5

    Matlab fzero function

    Hi All,
    Below there is some piece of a code for a problem I try to solve. Unfortunately, I am not sure about the red part of the code. Always get an error message in Matlab. Does anybody know where the problem lies? I believe that the "fzero" function in matlab may have problem to handle the f_evaldeltaHV (P,T,x) function which by itself are functions and contatain the iteration variable T (temperature).

    V=F*VF; % Vapor stream in mol/s
    L=F-V; % Liquid stream in in mol/s
    P=1;
    Tf=350; %Temperature of feed
    T=250; % Guess temperature
    % 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]

    f_energy_balance=F*f_evaldeltaHV(P,Tf,z)+Q V*f_evaldeltaHV(P,T,y)-L*f_evaldeltaHL(P,T,x);
    Tnew=fzero(f_energy_balance,T,[],F,Q,V,L,P,T,x,y,z,Tf);


    Tchange=T-Tnew;
    % if abs(Tchange)<1e-5
    % break;
    % end;
    % T=Tnew
    %end;

    Cheers and many thanks in advance.
    Martin
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by MartinKeppler View Post
    Hi All,
    Below there is some piece of a code for a problem I try to solve. Unfortunately, I am not sure about the red part of the code. Always get an error message in Matlab. Does anybody know where the problem lies? I believe that the "fzero" function in matlab may have problem to handle the f_evaldeltaHV (P,T,x) function which by itself are functions and contatain the iteration variable T (temperature).

    V=F*VF; % Vapor stream in mol/s
    L=F-V; % Liquid stream in in mol/s
    P=1;
    Tf=350; %Temperature of feed
    T=250; % Guess temperature
    % 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]

    f_energy_balance=F*f_evaldeltaHV(P,Tf,z)+Q V*f_evaldeltaHV(P,T,y)-L*f_evaldeltaHL(P,T,x);
    Tnew=fzero(f_energy_balance,T,[],F,Q,V,L,P,T,x,y,z,Tf);


    Tchange=T-Tnew;
    % if abs(Tchange)<1e-5
    % break;
    % end;
    % T=Tnew
    %end;

    Cheers and many thanks in advance.
    Martin
    Your f_energy_balance is not a function, it has either to be a function definition in an .m file or an in-line anonymous function.

    See the help of fzero: Find root of continuous function of one variable - MATLAB

    (it will also tell you what to do with all those extra parameters.)

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jan 2010
    Posts
    5

    Many Thanks

    Thank you very much. Actually I figured out that by using a handle function you can solve the problem.

    example:
    f_energy_balance=@ (T) F*f_evaldeltaHV(P,Tf,z)+Q V*f_evaldeltaHV(P,T,y)-L*f_evaldeltaHL(P,T,x);
    Tnew=fzero(f_energy_balance, T)

    Like this is works. So I have to say that the help of Matlab is not very user friendly at all, and it is rather by luck I understood what a "handle" is....

    But many thanks for the hint CB
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by MartinKeppler View Post
    Thank you very much. Actually I figured out that by using a handle function you can solve the problem.

    example:
    f_energy_balance=@ (T) F*f_evaldeltaHV(P,Tf,z)+Q V*f_evaldeltaHV(P,T,y)-L*f_evaldeltaHL(P,T,x);
    Tnew=fzero(f_energy_balance, T)

    Like this is works. So I have to say that the help of Matlab is not very user friendly at all, and it is rather by luck I understood what a "handle" is....

    But many thanks for the hint CB
    That is not a "handle function" but a "function handle" to an anonymous function. Which is one of the things mentioned in my earlier post.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 2
    Last Post: February 19th 2011, 05:54 AM
  2. need a matlab function
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 1st 2011, 10:52 PM
  3. is there any function in MATLAB?
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 4th 2010, 01:57 AM
  4. MATLAB function help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: March 23rd 2010, 01:53 PM
  5. Matlab while function
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 9th 2009, 11:46 PM

Search Tags


/mathhelpforum @mathhelpforum