# A question about the Newton method in SNES

**URL:** https://community.freefem.org/t/a-question-about-the-newton-method-in-snes/3158
**Category:** General Discussion
**Created:** [April 29, 2024, 4:02am UTC](https://community.freefem.org/t/a-question-about-the-newton-method-in-snes/3158 "2024-04-29T04:02:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)
#### Post date: [April 29, 2024, 4:02am UTC](https://community.freefem.org/t/a-question-about-the-newton-method-in-snes/3158/1 "2024-04-29T04:02:14Z")

</div>

Dear all,

I am trying to use petsc SNES to solve the nonlinear equation instead of doing Newton iteration by hand. I find there are many options for -snes\_type and -snes\_linesearch\_type. The default option is the Line Search Newton. I tried the “-snes\_linesearch\_type basic” , but I find that the results are different with that I get with standard Newton iteration by using loops and only ksp solvers in some cases, and even sometimes the SNES just diverge (I check the ksp solver for mat converges when I use snes ).

Is there many differences between the line search Newton and standard Newton iteration?( I think they should be mostly the same, in some cases I get the same results but sometimes different) or any options in the SNES that can help me do the standard Newton iteration?

Thanks very much .

---

<div class="post-metadata">

### Author: ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)
#### Post date: [April 29, 2024, 4:08am UTC](https://community.freefem.org/t/a-question-about-the-newton-method-in-snes/3158/2 "2024-04-29T04:08:58Z")

</div>

One reason I have tried is that when doing standard Newton Iteration, I sometimes introduce one damping parameter alpha(just smaller than one) and updated my solution with

u = u - alpha\*du

Within petsc SNES, I use the option “-snes\_linesearch\_damping” but still there exists the problem that sometimes SNES with “-snes\_linesearch\_type basic” will diverge but standard Newton Iteration converge.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [April 29, 2024, 5:22am UTC](https://community.freefem.org/t/a-question-about-the-newton-method-in-snes/3158/3 "2024-04-29T05:22:26Z")

</div>

`-snes_linesearch_type basic` should yield the same results as the Newton method written from scratch naively.

---

<div class="post-metadata">

### Author: ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)
#### Post date: [April 29, 2024, 6:43am UTC](https://community.freefem.org/t/a-question-about-the-newton-method-in-snes/3158/4 "2024-04-29T06:43:58Z")

</div>

Thanks for your fast reply. I also think there should not be different. I will check the codes more carefully.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [April 29, 2024, 6:47am UTC](https://community.freefem.org/t/a-question-about-the-newton-method-in-snes/3158/5 "2024-04-29T06:47:46Z")

</div>

One way to check is to use the two `func`s you are using in `SNESSolve()` (Jacobian and residual evaluations) in your hand-written Newton method.
