Calling a function handle inside a function
Afficher commentaires plus anciens
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;
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Function Handles dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!