# Using Optim.jl with only\_fg!, what is the "Function value" that prints in the trace?

**URL:** <https://discourse.julialang.org/t/using-optim-jl-with-only-fg-what-is-the-function-value-that-prints-in-the-trace/87013>\
**Category:** General Usage\
**Tags:** optimization\
**Created:** [September 9, 2022, 7:14pm UTC](https://discourse.julialang.org/t/using-optim-jl-with-only-fg-what-is-the-function-value-that-prints-in-the-trace/87013 "2022-09-09T19:14:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pluie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pluie/32/35949_2.png) [@pluie](https://discourse.julialang.org/u/pluie)\
**Post date:** [September 9, 2022, 7:14pm UTC](https://discourse.julialang.org/t/using-optim-jl-with-only-fg-what-is-the-function-value-that-prints-in-the-trace/87013/1 "2022-09-09T19:14:23Z")

</div>

I am trying to execute the following optimization.

```julia
res = optimize( Optim.only_fg!((F, G, Az)->fg!(F,G,first(Az),x,z)), [100000.0],[500000.0],[400000.0],Fminbox(GradientDescent()),Optim.Options(iterations=10,show_trace=true,f_tol=1e-7,extended_trace=true,g_tol=1e-8))

```

where I have defined

```julia
function fg!(F,G,Az,xVal,zVal)
  # common computations not done in this example
  if G != nothing
   	G .= dX3dAz(Az,xVal,zVal)
  end
  if F != nothing
    return X3(Az,xVal,zVal)
  end
end

```

When I look at the trace printout, the three columns are: `Iter Function value Gradient norm`. The value printed out for “Function value” does not match what I would expect for my function `X3`. Could someone explain what exactly the “Function value” is being calculated from? Is it a weighting from the function and gradient? Is this discussed in the documentation anywhere? I wasn’t able to find anything.

Also, I know I haven’t included the functions `X3` and `dX3dAz` as they very long, complicated expressions. However, I hope my question can be answered regardless. Thank you.
