Calling a function handle inside a function

I am writing a code to do the gradient method. First, I take a function [f0], I supply also the gradient [g1]. With the value of the function gradient I have a function with only one variable [fm1]. This function [fm1] is a function handle which I need to insert into my function busca1D_dico. Does anyone know how I can use a function handle inside a function I made?
%variables
x0 = [-1.2;1];
I = [0;5];
e = 1e-3;
lf = 2.1;
cont = 0;
%equations
f0 = 10*(x0(2)-x0(1)^2)^2-(1-x0(1))^2;
g1 = [-40*x0(1)*(x0(2)-x0(1)^2)-2*(1-x0(1));20*(x0(2)-x0(1)^2)];
fm1 = @(a) 10*((x0(2)-a*g1(2))-(x0(1)-a*g1(1))^2)^2+(1-(x0(1)-a*g1(1)))^2;
%calling a function
[a1] = busca1D_dico(I,e,lf,fm1);
x1 = [(x0(1)-a1*g1(1));(x0(2)-a1*g1(2))];
f1 = 10*(x1(2)-x1(1)^2)^2-(1-x1(1))^2;

 Accepted Answer

Example:
function result = busca1D_dico(I,e,lf,fun)
x = I(1):e:I(2);
y = fun(x);
...
That is, you accept the function handle as a parameter, and you give the name of the parameter followed by the name of the inputs.

More Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!