I need some help curve-fitting a set of data. In the past I have been able
to curve-fit a linear or a polynomial function, but now I need to figure out
a way to curve-fit a hyperbolic tan (tanh) function. Does anyone have
experience in using such a function?
Any help in this regard will be greatly appreciated.
Faisal
--
Mohammad Faisal Zaman
E-Mail: md.f...@resnet.gatech.edu
Do you have the Optimization toolbox? If so, you need lsqnonlin.
Otherwise you can adapt fzero or fminsearch to do what you need,
to find the minimum of the least-squares error surface.
- Randy
A simple-minded start:
Assume we want to fit y = a*tanh(b*x+c)+d to data (xx, yy)(1:n).
Since d-a <= y <= d+a, set d+a = max(yy), d-a = min(yy). This gives a
and d.
Suppose yy = 0 at x = x0. Then b*x0+c = 0.
We need one more relation.
Suppose y'(x0) = s0 (the slope when yy = 0).
Since tanh'(x) = 1/cosh^2(x),
y'(x) = a*b/cosh^2(b*x+c) so
s0 = y'(x0) = a*b so b = s0/a and c = -b*x0.
If the y values are not a full tanh curve, but do have a half curve
(-inf to 0 or 0 to inf), estimate a and d from, say,
d+a = max(yy), a = yy(where yy has maximum slope).
Anyway, this could give reasonable starting parameter values
for a nonlinear fit.
Martin Cohen