How can I run this function?
Mostrar comentarios más antiguos
Hi, I can't run this function called gradiente. f should be a function of two variables, grad should be the gradient of that function, x0 is a vector with number of elements like the number of variables; toll and maxiter should be numbers. I have difficult to run it
function [ x,fx ,iter,x_vett]=gradiente(f,grad,x0,toll,maxiter)
% x = ottimo
% fx = valore ottimo
% iter = numero di iterazioni
x=x0;
fx=feval(f,x(1),x(2));
d=-feval(grad,x(1),x(2));
err=norm(d);
iter=0;
x_vett=[x];
while (err>toll) & (iter <=maxiter)
alpha=linesearch(f,grad,x,d);
x=x+alpha*d;
x_vett=[x_vett,x];
d=-feval(grad,x(1),x(2));
err=norm(d);
iter=iter+1;
end
fx=feval(f,x(1),x(2));
if (err>toll) & iter>maxiter
error('Hai superato il numero max di iterazioni!!!')
end
this is the code for the function "linesearch"
function alpha=linesearch(f,grad,x,d)
gamma=0.1;
sigma=1/4;
alpha=1;
alphamin= 10^(-3);
xnew=x+alpha*d;
while feval(f,xnew(1),xnew(2))>feval(f,x(1),x(2))+... % I cond. di Wolfe
gamma*alpha*feval(grad,x(1),x(2))'*d & alpha>alphamin
alpha=sigma*alpha;
xnew=x+alpha*d;
end
Can anyone try to run the function "gradiente" and tell me the inputs in the command window?
Respuestas (1)
Azzi Abdelmalek
el 10 de Jul. de 2015
Assign values to f,grad,x0,toll,maxiter
f=
grad=
x0=
toll=
maxiter=
[ x,fx ,iter,x_vett]=gradiente(f,grad,x0,toll,maxiter)
1 comentario
DIEGO FOSSO
el 10 de Jul. de 2015
Categorías
Más información sobre Spline Postprocessing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!