Undefined function or variable ' t ',how can I difine ' t ' correctly?

4 visualizaciones (últimos 30 días)
Hi!
I have defined a function which is:
function [ xs Fxs ] = RevNewton( F, grad, Hess, x, x0 )
where 'F' is the function of 'x'(can be a scalar or a vector),'x0' is the initial value of 'x','grad' and 'Hess' are the gradient vector and Hesse matrix respectively.
In this funtion,I used a varieble 't', which I haven't defined first, to transform the function F(x) to a function F(t) by using:
subs(F,{x},{x0+t.*p}),
where 'p' is a numerical vector.when using this function,I got an error:
??? Undefined function or variable 't'.
Error in ==> RevNewton at 10
fhandle=eval(['@(t)',vectorize(subs(F,{x},{x0+t.*p}))]);

Respuesta aceptada

Star Strider
Star Strider el 7 de Jun. de 2014
If I understand ‘9 th row’ correctly, why not just state it as:
fhandle = @(t) vectorize(subs(F,{x},{x0+t.*p}));
Also consider using matlabFunction.
  2 comentarios
David W.
David W. el 8 de Jun. de 2014
thank you very much,with you suggestion ,I realised that 'eval' is not needed!
Star Strider
Star Strider el 8 de Jun. de 2014
My pleasure!
Glad we got that sorted!

Iniciar sesión para comentar.

Más respuestas (1)

MA
MA el 7 de Jun. de 2014
put syms t before giving function F to the program
  6 comentarios
David W.
David W. el 7 de Jun. de 2014
function [ xs Fxs ] = RevNewton( F, grad, Hess, x, x0 )
Hess
f0 = subs(F,{x},{x0});
g0 = subs(grad,{x},{x0});
HS=0;
while HS==0
G = subs(Hess,{x},{x0});
if det(G)==0
p=-g0;
fhandle=eval(['@(t)',vectorize(subs(F,{x},{x0+t.*p}))]);
[a b]=searchint(fhandle,0,1);
[tg f]=goldenSM(fhandle,0.1,a,b);
xx=x0+tg.*p;
g=subs(grad,{x},{xx});
else
x1=x0-G\g0;
f1=subs(F,{x},{x1});
[xx f g]=revise(F,f0,f1,g0,x0);
end
HS = HS(x0,xx,f0,f,g);
x0 = xx;
f0 = f;
g0 = g;
end
xs = xx;
Fxs = f;
function [xx f g]=revise(F,f0,f1,g0,x0)
if f1<f0
g=subs(grad,{x},{x1});
f=f1;
xx=x1;
else
if abs(g0.*p)/(norm(g0,2)*norm(p,2))<=0.1
p=-g0;
else
if (g0.*p)/(norm(g0,2)*norm(p,2))<=0.1
p=-G\g0;
else
p=G\g0;
end
end
fhandle=eval(['@(t)',vectorize(subs(F,{x},{x0+t.*p}))]);
[a b]=searchint(fhandle,0,1);
[tg f]=goldenSM(fhandle,0.1,a,b);
xx=x0+tg.*p;
g=subs(grad,{x},{xx});
end
end
end
David W.
David W. el 7 de Jun. de 2014
the error is in the 9th. row

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by