Saturday, 31 August 2013

Calling a function from inside another function?

Calling a function from inside another function?

I have 3 short functions that I've written inside 3 separate m files in
Matlab.
The main function is called F_ and accepts one input argument and returns
a vector with 3 elements.
Element 1 and 2 of the output from F_ are (supposed to be) calculated
using the functions in the other 2 m files, lets call them theta0_ and
theta1_ for now.
Here's the code:
function Output = F_(t)
global RhoRF SigmaRF
Output = zeros(3,1);
Output(1) = theta0(t);
Output(2) = theta1(t) - RhoRF(2,3)*sqrt(SigmaRF(2,2))*sqrt(SigmaRF(3,3));
Output(3) = -0.5*SigmaRF(3,3);
end
and
function Output = theta0_(t)
global df0dt a0 f0 SigmaRF
Output = df0dt(t) + a0 + f0(t) + SigmaRF(1,1)/(2*a0)*(1-exp(-2*a0*t));
end
and
function Output = theta1_(t)
global df1dt a1 f1 SigmaRF
Output = df1dt(t) + a1 + f1(t) + SigmaRF(2,2)/(2*a1)*(1-exp(-2*a1*t));
end
I've created handles to these functions as follows:
F = @F_;
theta0 = @theta0_;
theta1 = @theta1_;
When I run F_ via it's handle with any value of t I get the following error:
F_(1)
Undefined function 'theta0' for input arguments of type 'double'.
Error in F_ (line 9)
Output(1) = theta0(t);
Please assist. What am I doing wrong here?
I only want to be able to call one function from within another.

No comments:

Post a Comment