How can I run this function?

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?

回答(1 个)

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 个评论

I know this are the inputs, my problem is the values of this inputs.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Spline Postprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by