Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
function file construction

Subject: function file construction

From: Dhrue

Date: 24 May, 2009 02:11:01

Message: 1 of 3

I am trying to create a function file which takes in other function files as inputs. In this problem I successfully created fy.m and zprime_x.m. I want to use fy.m & zprime_x.m in the third function file x_fun.m. This is where I am stuck. Please help!!

File fy.m
function y = fy(r,w,z)
global A alpha v delta y_pw1 y_pw2 y_pw3 y_pw4
y=A*((A*(1-alpha)*v)^y_pw1)*((alpha/(1-alpha))^y_pw2)*((1/(r+delta))^y_pw3)*(1/w)^y_pw4*z;
end

File zprime_x.m
function zprime_partial= zprime_x(z,x)
global theta1 theta2
zprime_partial=theta2*(z^theta1)*(x^(theta2-1));
end

I want to create a third function file which will take fy() and zprime_x() as inputs....somewhat like this...but this is not working.....

File x_fun.m
function ability_investment = x_fun(fy,zprime_x,r)
global v P
x_fun=(1+r)/P-(1-v)*(fy/z)*zprime_x;
end

In my main file I will later apply fzero on x_fun to solve for x (after i assigned values to the rest of the variables)

Subject: function file construction

From: Steven Lord

Date: 24 May, 2009 02:49:32

Message: 2 of 3


"Dhrue " <dhritiman-bhattacharya@uiowa.edu> wrote in message
news:gvaabl$766$1@fred.mathworks.com...
>I am trying to create a function file which takes in other function files
>as inputs. In this problem I successfully created fy.m and zprime_x.m. I
>want to use fy.m & zprime_x.m in the third function file x_fun.m. This is
>where I am stuck. Please help!!

*snip*

Use function handles.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bresuxt-1.html#bresu3n-5

See the help for FZERO for a simple example.

--
Steve Lord
slord@mathworks.com

Subject: function file construction

From: Dhrue

Date: 24 May, 2009 05:34:01

Message: 3 of 3

"Steven Lord" <slord@mathworks.com> wrote in message <gvacjg$km9$1@fred.mathworks.com>...
>
> "Dhrue " <dhritiman-bhattacharya@uiowa.edu> wrote in message
> news:gvaabl$766$1@fred.mathworks.com...
> >I am trying to create a function file which takes in other function files
> >as inputs. In this problem I successfully created fy.m and zprime_x.m. I
> >want to use fy.m & zprime_x.m in the third function file x_fun.m. This is
> >where I am stuck. Please help!!
>
> *snip*
>
> Use function handles.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bresuxt-1.html#bresu3n-5
>
> See the help for FZERO for a simple example.
>
> --
> Steve Lord
> slord@mathworks.com
>




Thanks for your promt reply. I am still confused about this. I could not understand the contents of the link in the context of my problem. I could not find an example which uses atleast two function files as input arguments in another function file. I really appreciate your help.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us