<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div> We also have support for this built into SNES. For example, you provide the analytic to SNES which then compute via differencing, mostly to check if the analytic implementation was correct. You can run an entire set of SNESSolve with this turned on and it will check at all vectors the Jacobian is computed how closely the match is (that is it does not just compare the two for a single vector).<div><br></div><div> -snes_test_jacobian <optional threshold> </div><div><br></div><div>see the routine SNESTestJacobian() which as the code that compares the matrices element by element etc. See also <a href="https://urldefense.us/v3/__https://petsc.org/release/manual/snes/*checking-accuracy-of-derivatives__;Iw!!G_uCfscf7eWS!ZMikDTtuiW1VhZZbem68GDU-ADoEf8_Mok1dQ18Er-vr4DStxjq-Ula5ZHd0tLvVSXoLbI-NNFYPuV20Gu08oDI$">https://petsc.org/release/manual/snes/#checking-accuracy-of-derivatives</a></div><div><br></div><div><br></div><div> Barry</div><div><br></div><div><br></div><div><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Jan 2, 2025, at 4:51 PM, Stefano Zampini <stefano.zampini@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><p dir="ltr">MatAXPY for the difference, MatNorm for the relative error</p>
<br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, Jan 2, 2025, 22:32 Hammond, Glenn E via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<div class="m_-2477202393305587051WordSection1"><p class="MsoNormal">PETSc Users,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I want to compare two Jacobians matrices (one with derivatives calculated analytically; the other numerically). I want to apply relatives and/or absolute tolerances. Does anyone know if such capability is built into PETSc? I cannot find
anything other the MatEqual() with compares down to the bit. Otherwise, I plan to use MatGetValues() and compare the elements individually. Just hoping there is something more convenient hidden somewhere.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Thanks,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Glenn<u></u><u></u></p>
</div>
</div>
</blockquote></div>
</div></blockquote></div><br></div></body></html>