# How to fix some parameters when least-squares-fitting using \`NonlinearSolve\`?

**URL:** <https://discourse.julialang.org/t/how-to-fix-some-parameters-when-least-squares-fitting-using-nonlinearsolve/124451>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 5, 2025, 4:05pm UTC](https://discourse.julialang.org/t/how-to-fix-some-parameters-when-least-squares-fitting-using-nonlinearsolve/124451 "2025-01-05T16:05:01Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![thudjx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thudjx/32/15231_2.png) [@thudjx](https://discourse.julialang.org/u/thudjx)\
**Post date:** [January 7, 2025, 9:28am UTC](https://discourse.julialang.org/t/how-to-fix-some-parameters-when-least-squares-fitting-using-nonlinearsolve/124451/5 "2025-01-07T09:28:03Z")

</div>

Not sure if I understand you correctly.  
`residualfn!` only modify `du` in-place, so if `du` is preallocated, it is easy to be retrieved from the cache and thus have a performance gain. But I am bit confused, if no parameter in the model is fixed, the problem is defined as `prob = NonlinearLeastSquaresProblem(NonlinearFunction(lossfn!, resid_prototype = similar(ydata)), u0, data)` (as [here](https://discourse.julialang.org/t/least-squares-with-sciml-nonlinearsolve-jl-how-to/113074/14), and `du` is not preallocated but a performance gain is expected.  
Here in my case, where some parameters of `u` are transfered by closure:  
`prob = NonlinearLeastSquaresProblem(NonlinearFunction((dp, p, data) -> residual!(dp, [p; t₀], data), resid_prototype = similar(ys)), [y0, a, τ], (xs, ys))`  
I don’t get how I lose the performance gain.  
Would you please demonstrate more? I would really appreciate that!

---

_[View the full topic](https://discourse.julialang.org/t/how-to-fix-some-parameters-when-least-squares-fitting-using-nonlinearsolve/124451)._
