Variational form vs Matrix form do not give the same results

I try to solve the Klein-Gordon equation (already posted by Prof. François Bouchut), but using variational form. What surprises me is that the two methods give (slightly ) different results. I think that the reason is: the initialization, because when I start with a very close U1 (see line 59 kg-VF.edp) the two methods give exactly the same results. My question is: How can I enhance the initialization (compute U1 very accurately) (in variational form) when the exact solution is unknown? Attached here

kg-VF.edp (3.5 KB)

kg-Matrix.edp (3.6 KB)

are the two codes.

In your file kg-FV.edp, line 55, the test “if (res > 1e-10)” should be “if (res < 1e-10)”
Also you should not modify U0 (line 56 has to be removed). Line 53 has also to be removed.

Thank you so much, now it works fine. I really appreciate your help.