Why do I keep getting this error message?

I need to approximate the Jacobian. Here is my code, I cant seem to understand function handles very well, please help me!
function [ Jac ] = finitediffJac( usrfun, method, x, h ) [xrow, xcol]=size(x); if xcol>1 error('too many coloumns'); end xp=x; %[funrow,funcol]= size(feval(userfun,x)); if funcol>1 error('user function has too many columns.'); end Jac=zeros(funrow,xrow); %user inputs desired function, method of choice, a value for x, and a step % [hrow,hcol]= size(h); if hrow~=xrow error('h needs to have the same rows as x'); end for xcount=1:xrow if strcmpi(method, 'forward');
%if the user types in forward method the following finite differncing
%method will be used
Jac(:,xcount)=feval(userfun,(xp +h(xcount)))-feval(usrfun,xp)./h(xcount);
elseif strcmpi(method, 'backward');
%if the user types in backward method the following finite differncing
%method will be used
Jac(:,xcount)= (feval(usrfun,xp)- feval(usrfun,(xp-h(xcount))))./h(xcount);
elseif strcmpi(method, 'central');
%if the user types in central method the following finite differncing
%method will be used
Jac(:,xcount)= (feval(usrfun,(xp +h(xcount)))-feval(usrfun,(xp-h(xcount))))./2*h(xcount);
else
disp(' method not recognized')
end
end
end
*Terminal input and output***
>> usrfun = {@(x) (7*x(1)-x(1)*exp(x(3))+37);@(x)(sqrt(x(2)*x(3)));@(x) (12*x(1)*x(3).^3-6*x(2) +37);}
usrfun =
@(x)(7*x(1)-x(1)*exp(x(3))+37)
@(x)(sqrt(x(2)*x(3)))
@(x)(12*x(1)*x(3).^3-6*x(2)+37)
>> function [ Jac ] = finitediffJac( usrfun, 'forward', x, h )
function [ Jac ] = finitediffJac( usrfun, 'forward', x, h )
|
??????Error: Function definitions are not permitted in this context.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!