Suppose you are given some functional $S$, (with some 'Lagrangian' $L$) $$S[f]=\int_{t_i}^{t_f}L[f(t),f'(t)]dt$$ and you want to find the function $f$ that minimizes it, subject to some boundary conditions at $t_i$ and $t_f$. To be specific I'll consider the following case $$S[f]=\int_{0}^{t_{max}}\left(f'(t)\right)^2dt,$$ where $f(0)=\pi, f(t_{max})=0$. This is just minimized by a linear $f$, but my ultimate goal is to do this for a different problem which I can't solve analytically.
I wanted to discretize the problem and treat $f$ as a list of large number $n-1$ of variables, and then use FindMinimum in Mathematica for this purpose since I saw it implements the quasi-Newton BFGS approximation. But I am new to Mathematica and can't seem to figure out how to do this in practice.
This is what I've tried:
Setting up an initial trial solution f0
(which is just a shifted exponential in this case),
tMax = 10;
n = 100;
dt = tMax/n;
f0 = Table[\[Pi]/(1 - Exp[-tMax]) (Exp[-(i*dt)] - Exp[-tMax]), {i, 1,
n - 1}];
Defining a numerical derivative derList
, and the functional action
,
derList[f_, delta_] :=
1/delta Join[{1/2 (f[[2]] - \[Pi])},
ListConvolve[{1/2 , 0, -(1/2 )}, f], {-1/2 f[[Length[f] - 1]]}];
action[f_] := derList[f, 1] . derList[f, 1];
where I don't care so much about overall positive factors multiplying the functional, hence the use of 1 in action
rather than something more appropriate like dt
.
Now I want to use FindMinimum, but I can't seem to figure out the proper syntax. If I use
FindMinimum[action[f], {f, f0}]
it does not work. How should I set up this problem?
Just to be clear, in the end you can completely forget the motivation for this problem. action[f]
is just some positive real-valued function of n-1
variables given by the components of the list f
, and I have initial guesses for each one of those variables which are given by components of f0
. But I just do not know how to set up FindMinimum to work with lists in this way. I would rather not copy-paste in an explicit expression for action[f]
in terms of components, and write out 99 initial guesses, so I'm just looking for a way to avoid that.
f
is complex function? $\endgroup$NMinimize
. $\endgroup$