# Simplest way to have numerical FOC of a function?

**URL:** <https://discourse.julialang.org/t/simplest-way-to-have-numerical-foc-of-a-function/35754>\
**Category:** Optimization (Mathematical)\
**Created:** [March 9, 2020, 3:03pm UTC](https://discourse.julialang.org/t/simplest-way-to-have-numerical-foc-of-a-function/35754 "2020-03-09T15:03:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [March 9, 2020, 3:03pm UTC](https://discourse.julialang.org/t/simplest-way-to-have-numerical-foc-of-a-function/35754/1 "2020-03-09T15:03:34Z")

</div>

I have the following function for which I need to find the First Order Conditions with respect to one parameter, let’s say \mathbb{u}:

`J(u,v,Y,λ) = sum(skipmissing((Y-(u * v')) .^ 2))/2 + (λ/2) * (norm(u)^2 + norm(v)^2)`

(This is in the context of an exercise on Collaborative filtering; a machine learning tecnique)

The exercise is very simple, I can do it by hand. But I am wondering which is the best approach, in real life what one would use. Analytical analysis (SymPy) ?  
Or automatic differentiation? But in such case I would get a numerical gradient, while I need the result of the equation \partial L / \partial u = 0.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 9, 2020, 3:22pm UTC](https://discourse.julialang.org/t/simplest-way-to-have-numerical-foc-of-a-function/35754/2 "2020-03-09T15:22:37Z")

</div>

> [@sylvaticus](#):
>
> But in such case I would get a numerical gradient, while I need the result of the equation

Then you can solve for the result being `0` using a rootfinder algorithm? But if you actually have a closed form I would just use that.
