subroutine jfcn(n, w, jf)
real(4) w(n), jf(n,n)

! Broyden banded;
f1(u) =2+15*u*u
f2(u) =-1-2*u

jf =0.
x =w(1); y =w(2)
if( n>=3) z=w(3)

! Test1:
!f(1)=x*x +y*y -5.
!f(2)=y -exp(x) -1.

! jacobian:
!jf(1,1) =2*x; jf(1,2) =2*y
!jf(2,1) =-exp(x); jf(2,2) =1

!18-III
!f(1) =x+y+z*z-3.8
!f(2) =x*y*z+1.9
!f(3) =sqrt(x)+sqrt(y)-z*z-1.3

!jf(1,1) =1
!jf(1,2) =1
!jf(1,3) =2*z 

!jf(2,1) =y*z
!jf(2,2) =x*z
!jf(2,3) =x*y

!jf(3,1) =1./(2*sqrt(x))
!jf(3,2) =1./(2*sqrt(y))
!jf(3,3) =-2*z

! 19/I E: (2,1,-1)
!f(1) =x*x ++y*y +z*z-6.4
!f(2) =x*y*z +2.2
!f(3) =x +y-z*z-2.4

!jf(1,1) =2*x;   jf(1,2) =2*y;   jf(1,3) =2*z 
!jf(2,1) =y*z;   jf(2,2) =x*z;   jf(2,3) =x*y;

!jf(3,1) =1.;    jf(3,2) =1.;    jf(3,3) =-2*z

! Miel:
!f(1) =2*x*x*x -y*y -1
!f(2) =x*y*y*y -y -4

!jf(1,1) =6*x*x;   jf(1,2) =2*y;
!jf(2,1) =y*Y*y;   jf(2,2) =x*3*y*y -1;

!! Vahidi 2012:(0.5,0,-pi/6)
pi =asin(1.)
!x1 =w(1); x2 =w(2); x3 =w(3);

! Vahidi:
!f(1) =3*x1 -dcos(x2*x3)- 0.5
!f(2) =x1*x1 -81*(x2 + 0.1)**2 +dsin(x3) + 1.06
!f(3) =dexp(-x1*x2) + 20*x3 + (10*pi-3)/3

!jf(1,1) =3; jf(1,2) =x3*sin(x2*x3); jf(1,3) =x2*sin(x2*x3);
!jf(2,1) =2*x1; jf(2,2) =-81*2*(x2 + 0.1); jf(2,3) =cos(x3);
!jf(3,1) =-x2*exp(-x1*x2); jf(3,2) =-x1*exp(-x1*x2); jf(3,3) =20;!

! vah-2 (varianta)
!f(1) =3*x1 -cos(x2*x3)- 0.5
!f(2) =x1*x2 -81*(x2 + 0.1)/2 +sin(x3) + 1.06
!f(3) =exp(-x1*x2) + 20*x3 + (10*pi-3)/3

!jf(1,1) =3; jf(1,2) =x3*sin(x2*x3); jf(1,3) =x2*sin(x2*x3);
!jf(2,1) =x2; jf(2,2) =x1 -81/2; jf(2,3) =cos(x3);
!jf(3,1) =-x2*exp(-x1*x2); jf(3,2) =-x1*exp(-x1*x2); jf(3,3) =20;

! Powell Badly Scaled Function
! x* = (1.098...10?5, 9.106...), (9.106..., 1.098...10?5 )
! Initial: 2;3 => div.;     0.,9;

!f(1) =1E4*x*y -1
!f(2) =exp(-x) +exp(-y) -1.0001

!jf(1,1) =1E4*y;   jf(1,2) =1E4*x;
!jf(2,1) =-exp(-x);   jf(2,2) =-exp(-y);


! Broyden banded; n =4; r1=5; r2=1; i=1,n;
jf(1,:) =(/f1(w(1)), f2(w(2)), 0, 0/)
jf(2,:) =(/f2(w(1)), f1(w(2)), f2(w(3)), 0/)
jf(3,:) =(/f2(w(1)), f2(w(2)), f1(w(3)), f2(w(4))/)
jf(4,:) =(/f2(w(1)), f2(w(2)), f2(w(3)), f1(w(4))/)
 
END
