Infinite Series
eapurcel
I am trying to graph an infinite series (with cosh, sinh and sin in the function) for n=odd numbers but can't figure out how. Can I do this from the function grapher? Or does it need to be in the command line?
Thanks for your help!
For odd numbers : start the summing procedure with one and use a step size of two in the loop.
You might end up with something like this:
Wave FG_ParamWave
Variable x
//CurveFitDialog/
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 5
//CurveFitDialog/ FG_ParamWave[0] = nmax
//CurveFitDialog/ FG_ParamWave[1] = x0
//CurveFitDialog/ FG_ParamWave[2] = a
//CurveFitDialog/ FG_ParamWave[3] = n0
//CurveFitDialog/ FG_ParamWave[4] = step
Variable nmax = FG_ParamWave[0]
Variable x0 = FG_ParamWave[1]
Variable a = FG_ParamWave[2]
Variable n0 = FG_ParamWave[3]
Variable step = FG_ParamWave[4]
variable n, Result=0
If (step==0)
step=1
endif
if (nmax<n0)
return nan
endif
for (n=n0;n<nmax;n+=step)
Result+=a*sinh(n*(x-x0))
endfor
return Result
end
The two if statements prevent the grapher from being stuck with some coefficient combinations....
HJ
February 15, 2017 at 12:20 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
February 15, 2017 at 12:06 pm - Permalink
I'd keep an upper limit for the number of summands (it might be rather large than in the above example). It might be useful to detect non-convergence (divergence and oscillating cases) and will terminate the calculation in such a case (maybe you want to set a flag?).
HJ
February 15, 2017 at 02:55 pm - Permalink
A.G.
WaveMetrics, Inc.
February 17, 2017 at 09:41 am - Permalink
Specifically, I'm having a hard time with the indexing. As in assigning each value to the appropriate position in the matrix.
The formula for velocity looks like:
velocityP += (Pressure/(viscosity*L))*4*(H^2)/(pi)^3*(1/n^3)*(1-(cosh(n*pi*positionsx/H))/(cosh(n*pi*w/(2*H)))*sin(n*pi*(positionsy)/H))
with positionsx and positionsy being the input waves.
Thanks.
February 27, 2017 at 09:56 am - Permalink
I assume you mean, when the number of points in x and y are equal, velocityP will be an N x N matrix. To index x from top to bottom (row values) and y from left to right (column values), I believe that you need this notation ...
You can switch the p and q indices to rotate the matrix with x left to right and y top to bottom.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
February 27, 2017 at 12:51 pm - Permalink