help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## Re: Problems with functions

 From: Tatsuro MATSUOKA Subject: Re: Problems with functions Date: Wed, 20 Jul 2016 12:22:56 +0900 (JST)

```----- Original Message -----

> From: mat_hunt
> To: help-octave> Cc:
> Date: 2016/7/20, Wed 05:37
> Subject: Problems with functions
>
> 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.
>

This is not an answer but a comment.

You can calculate numerical jacobinan function "jacobs" in the optim package.

http://octave.sourceforge.net/optim/function/jacobs.html

Tatsuro

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]