Re: How to specify the gradient of this function?
- To: mathgroup at smc.vnet.net
- Subject: [mg125058] Re: How to specify the gradient of this function?
- From: Ray Koopman <koopman at sfu.ca>
- Date: Mon, 20 Feb 2012 02:46:23 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jhqmcf$f66$1@smc.vnet.net>
On Feb 19, 3:28 am, Sam Takoy <sam.ta... at yahoo.com> wrote:
> Hi,
>
> If I could ask you to take a look at this code:
>
> objF[x_, v_] := (x - 2)^4 + Norm[v]^2;
> FindMinimum[objF[x, v], {{x, 1}, {v, {1, 1, 1, 1}}}, StepMonitor :>
> Print[x, " ", v]]
>
> My objF takes a number and a vector. Is there a way to specify a
> gradient for a function with such a mix of inputs?
>
> Many thanks in advance,
>
> Sam
f[x_,v_] := (x-2)^4 + v.v
FindMinimum[f[x,v],{{x,1},{v,{1,1,1,1}}}]
{3.318844318129849*^-29, {x -> 2.0000000759008576,
v -> {6.429098305538346*^-19, -1.2225510287673918*^-18,
2.4867595862469272*^-18, -1.811816954191843*^-18}}}
g[x_,v_] := Flatten@{4(x-2)^3, 2v}
FindMinimum[f[x,v],{{x,1},{v,{1,1,1,1}}}, Gradient :> g[x,v]]
{6.993693241863676*^-29, {x -> 2.0000000914485123,
v -> {8.970026517861784*^-20, 8.970026677061437*^-20,
8.970026036695592*^-20, 8.970026835929654*^-20}}}