0
$\begingroup$

Let us suppose we have a coefficient vetor:

coeff = {a0, a1, b1, a2, b2, ..., an, bn} 

with a total of (2*n + 1) elements. Those coefficients are applied in a Fourier series, such as:

enter image description here

I need to calculate both Jacobian (J) and Hessian (H) matrices from the coefficients, in the form:

Transpose[J] = 

enter image description here

and

H = 

enter image description here

both evaluated in a range of points x = {1, ... M}. Could anyone help me build the matrices J and H?

$\endgroup$
1
  • $\begingroup$ So if I am understanding correctly, you would want the first column of Transpose[J] to look like {0.5, Cos[1],...,Cos[n],Sin[1],...,Sin[n]}? $\endgroup$
    – ydd
    Commented Aug 9, 2023 at 17:23

1 Answer 1

1
$\begingroup$

This is pretty easy. Note, I am using indexed variables instead of subscripts because these give less problems than subscripted variables:

For an example I use n=2, m=3. We first create the matrices without the special first row:

n = 2; m = 3;
rows0 = Table[0.5, m];
rows1 = Table[Cos [i x[j]], {i, n}, {j, m}];
rows2 = Table[Sin[i x[j]], {i, n}, {j, m}];
jac = Join[rows1, rows2];

hess = Table[ jac[[;; m, i]] . jac[[;; m, i]] + 
    jac[[m + 1 ;;, i]] . jac[[m + 1 ;;, i]], {i, 1, m}];
hess = DiagonalMatrix[hess] ;

Now we add the special rows and columns:

PrependTo[hess, Table[0, m]];
hess = Transpose[Prepend[Transpose@hess, Table[0, m + 1]]];
hess[[1, 1]] = rows0 . rows0;
hess // MatrixForm

PrependTo[jac, rows0] // MatrixForm

enter image description here

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.