[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problems with functions
From: |
mat_hunt |
Subject: |
Problems with functions |
Date: |
Tue, 19 Jul 2016 13:37:14 -0700 (PDT) |
I have defined a function:
function y=f(x)
y_1=x(1)-x(2)+x(3)-2;
y_2=2*x(1)-x(2)+x(3)-3;
y_3=2*x(1)+x(2)-x(3)-1;
y=[y_1 y_2 y_3];
endfunction
and I have written a function to compute the Jacobian of that function:
function J=jacobian(func,x)
% computes the Jacobian of a function
n=length(x);
fx=feval(func,x);
eps=1.e-8; % could be made better
xperturb=x;
for i=1:n
xperturb(i)=xperturb(i)+eps;
J(:,i)=(feval(func,xperturb)-fx)/eps;
xperturb(i)=x(i);
endfor;
endfunction
when I use the command:
jacobian(f,[1 1 1])
I get the error:
error: 'x' undefined near line 2 column 5
error: called from:
error: /home/mat/Matlab programs/f.m at line 2, column 4
error: evaluating argument list element number 1
What is going on? The code was working perfectly fine 10 minutes ago and now
it's throwing up errors.
--
View this message in context:
http://octave.1599824.n4.nabble.com/Problems-with-functions-tp4678670.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Problems with functions,
mat_hunt <=