Call a function with inputs from different sources
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Samuel Mustapha
il 14 Feb 2015
Commentato: Samuel Mustapha
il 15 Feb 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 Commenti
Risposta accettata
Andrei Bobrov
il 14 Feb 2015
Modificato: Andrei Bobrov
il 14 Feb 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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!