I am trying to create a function from R^n to R^n such that I can evaluate that function and eventually compute the gradient. Here is what i wrote (a modification of one of the post): f1=@(x_1,x_2) (x_1-2)^2+x_2;
f2=@(x_1,x_2) sqrt(x_2-1);
ff = {f1; f2};
F = @(x) cellfun(@feval,ff(:),num2cell(x(:)));
F([2 2]) But I am getting the following error: ??? Input argument "x_2" is undefined. Error in ==> @(x_1,x_2)(x_1-2)^2+x_2
Error in ==> @(x)cellfun(@feval,ff(:),num2cell(x(:)))
What am I doing wrong?
Thanks for your help in advance!

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 20 de Feb. de 2012

0 votos

f1=@(x_1,x_2) (x_1-2)^2+x_2;
f2=@(x_1,x_2) sqrt(x_2-1);
ff = {f1; f2};
x = [5 7];
F = @(x)cellfun(@(x,y)x(y{:}),ff,repmat({num2cell(x)},2,1));
F(x)

1 comentario

Eddy
Eddy el 20 de Feb. de 2012
Thanks a lot!!!!!!!!!
I work perfectly.

Iniciar sesión para comentar.

Más respuestas (1)

Eddy
Eddy el 20 de Feb. de 2012

0 votos

Thanks a lot!!!!!!!!! It works perfectly.

Etiquetas

Preguntada:

el 20 de Feb. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by