How do I call two function statements in a main program, and how to run it?
    5 views (last 30 days)
  
       Show older comments
    
    Arvind Sharma
 on 18 Oct 2017
  
    
    
    
    
    Commented: Arvind Sharma
 on 20 Oct 2017
            I have all parameters in the main program and want to use two function statements.
%----------------
function [mu]=mu(emass,ncarrier,kelvin,rerr)
return
%----------------
and the other :
function [fermi]=fermi(beta,energy,mu1)
return
These functions input values are defined in main program:
muhh=mu(mhh,ncarrier,kelvin,rerr)%Call mu chemical potential function for holes
mue=mu(me,ncarrier,kelvin,rerr) %Call mu chemical potential function for electrons
and
fhh=fermi(beta,Ehh,muhh); %Call Fermi function for holes
fe=fermi(beta,Ee,mue);
How do I call these function statements?
0 Comments
Accepted Answer
  Athos Garcia
 on 18 Oct 2017
        If you're using a script save the 2 functions in separate files and just call it like you did. But if your main program is also a function just remember to put the functions before the 'end' of the main program, like this:
function mainProgram()
% Define the variables values
mhh = 5;
ncarrier = 3;
% etc. etc.
muhh=mu(mhh,ncarrier,kelvin,rerr)%Call mu chemical potential function for holes
mue=mu(me,ncarrier,kelvin,rerr) %Call mu chemical potential function for electrons
fhh=fermi(beta,Ehh,muhh); %Call Fermi function for holes
fe=fermi(beta,Ee,mue);
    function [mu]=mu(emass,ncarrier,kelvin,rerr)
      mu = somethig;
    end
    function [fermi]=fermi(beta,energy,mu1)
      fermi = something;
    end
end % end of main program
More Answers (1)
  Image Analyst
      
      
 on 18 Oct 2017
        You are calling them correctly. As long as the variables (mhh, beta, etc.) that you are passing into the functions are already assigned values by your calling/main routine, you will be okay. Are you not observing that? Do you have a problem or error? If so, what?
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

