MATLAB: Undefined function or variable ‘ t ‘,how can I difine ‘ t ‘ correctly

undefined varieble

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}))]);

Best Answer

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.