Being new to Mathematica, I try to follow the suggestions of using NestList
, Map
, Table
instead of For/While
loops. Things have gone well so far, until I face this problem. I now want my function f
to calculate the next result, assume that it is f[f[f[x]]]
, using the two last results, namely f[f[x]]
and f[x]
. Can I achieve that goal without using For/While/Do loops?
To make the question more specific and easier to answer, this is my code:
LocalPotential[{v0_, va_, vab_}] := Module[
{potential = v0, grad = va, hess= vab, deltavab, next},
potential += deltaphi.grad + (1./2.)*(deltaphi.hess.deltaphi);
grad += hess.deltaphi;
hess = MyHessian[hess, grad];
next = {potential, grad, hess};
next
]
totallist = Table[
NestList[LocalPotential, {Potential0[n, 100.], Gradient0[n], DBH[n]}, nstep],
{i, 1, realisation}
];
I now want my function MyHessian
to calculate the next result using not just the previous one but also the one before that, i.e. va[n-1]
and va[n-2]
. What should I do? Thanks a million in advance!