Call a function with inputs from different sources
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Samuel Mustapha
el 14 de Feb. de 2015
Comentada: Samuel Mustapha
el 15 de Feb. de 2015
I am trying to input an anonymous function into a full function so that the full function can evaluate the anonymous function. The problem seems to be that the anonymous function is in a loop along with the full function and two of the variables in the anonymous function are meant to update at every interation but it doesn't seem to update.
for i = 1:5
d = -df(x)
%x = x+a*d;
ff = @(x, d) ((x(1)+a*d(1)) + 4*(x(2)+a*d(2)) - 3)^2 +...
(2*(x(1)+a*d(1)) + 5*(x(2)+a*d(2)) - 15)^2;
fff = @(a) ff(x, d);
if norm(d) == 0 || abs(norm(d)) < 0.1
break
end
alpha = Golden_section(fff, 0)
x = x +(alpha*d)
end
just wondering if there's any way for me to do this. As you can see above, I tried inputting the first two variables before calling the function in the golden section function but it just says that a does not exists.
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 14 de Feb. de 2015
Editada: Andrei Bobrov
el 14 de Feb. de 2015
try is it:
ff = @(x, d,a) ((x(1)+a*d(1)) + 4*(x(2)+a*d(2)) - 3)^2 +...
(2*(x(1)+a*d(1)) + 5*(x(2)+a*d(2)) - 15)^2;
x = ...; % input initial x
for i = 1:5
d = -df(x);
if norm(d) == 0 || abs(norm(d)) < 0.1
break
end
alpha = Golden_section(@(a)ff(x,d,a), 0);
x = x +(alpha*d);
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!