1 of 2

# Hat function is really used for galerkin method?

I am learning finite element method(galerkin method) for solving ode/pde.

when searching this topic, I often see examples using the hat functionUnitTriangle[x] as the basis function of the galerkin approximation.

I understand that the Galekin method is a method of expressing the objective function by the sum of a basis function and a coefficient, and solving the algebraic equation that is the result of integrating the residual with each basis function.

something like,
$$f=a_1 \phi_1+a_2 \phi_2+a_3 \phi_3+....+a_n \phi_n$$
where $$\int_{\Omega}\phi_i \phi_j =0$$
if
$$i\neq0$$

however,this is contrary to my intuition because linear combination of hat function that can be used for galerkin method doesn't provide practical approximation for the target function.

the below is example with 10 nodes which can't be used for galerkin method.

(*Hat function*)
kernel[j_] := UnitTriangle[x - j]
(*candicate solution*)
f = Total@Table[c[j]*kernel[j], {j, -10, 10, 1}];
(*L2 norm between target function and candicate solution*)
L2norm = Total[Power[Table[Sin[j] - (f /. x -> j), {j, -10, 10, 1}],
2
]
];
sol = Last@NMinimize[L2norm, Table[c[j], {j, -10, 10, 1}]];
Plot[{Sin[x], f /. sol}, {x, -10, 10}]


in the above,inner product of basis function doesn't 0.

 Table[
(*inner product of basis function*)
NIntegrate[kernel[j]*kernel[j + 1], {x, -10, 10}
],
{j, -10, 9}
]


{0.166667, 0.166667, 0.166667, 0.166667, 0.166667, 0.166667, \ 0.166667, 0.166667, 0.166667, 0.166667, 0.166667, 0.166667, 0.166667, \ 0.166667, 0.166667, 0.166667, 0.166667, 0.166667, 0.166667, 0.166667}

next is example which can be used for galerkin method where inner product of the basis functions are always 0.

(*Hat function*)
kernel[j_] := UnitTriangle[x - j]
(*candicate solution*)
f = Total@Table[c[j]*kernel[j], {j, -10, 10, 2}];
(*L2 norm between target function and candicate solution*)
L2norm = Total[Power[Table[Sin[j] - (f /. x -> j), {j, -10, 10, 1}],
2
]
];
sol = Last@NMinimize[L2norm, Table[c[j], {j, -10, 10, 2}]];
Plot[{Sin[x], f /. sol}, {x, -10, 10}]
Table[
(*inner product of basis function*)
NIntegrate[kernel[j]*kernel[j + 2], {x, -10, 10}
],
{j, -10, 8}
]


{0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0.}

it's clear something wrong...