! subrutina pentru calculul functiei F(W) si jacobianului JF(W): 
! X, X1, X2  = input
! ab = output
subroutine SUB_AB(X, X1, X2, a, b)
use work

implicit real(8) (a-h, o-z)
real(8)  X(ngl), X1(ngl), X2(ngl)
real(8)  a(ngl,ngl), b(ngl)

common /coef/	beta_h3, gama_h2, delta_h, &
				teta_beta_h3, teta1_gama_h2, teta2_delta_h

real(8) mx2(ngl), mw



! jacobianul:
A =M*teta2_delta_h + JG*teta_beta_h3 + JG1*teta1_gama_h2 + JF*teta_beta_h3
      

! termenii liberi bb = -F(w);
! Calculeaza M*X2:
do i =1,ngl
mw =0.
	do j=1,ngl
	mw =mw +m(i,j)*x2(j)
	enddo
mx2(i) =mw
enddo

!MX2 =matmul(M,X2)

b =-(MX2 +G +F -P)

end

