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;

 채택된 답변

Walter Roberson
Walter Roberson 2018년 3월 28일

0 개 추천

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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Function Handles에 대해 자세히 알아보기

질문:

2018년 3월 28일

답변:

2018년 3월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by