Infinite Series

Hello,

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!
I guess you will have to program that function yourself. As a start use the function grapher and create a new function with a single summand. Afterwards, click on show code. Now you can modify that function that it sums up the individual terms. You will need a finite upper limit (n_max) for that -- do not use "inf" (This might be a parameter for the function as well).
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:
Function MyFunc(FG_ParamWave, x) : FitFunc
    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
If your series is guaranteed to converge, you can monitor the size of the latest component compared to the size of the accumulated sum, and terminate when you are at acceptable accuracy.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Also think about convergence radius etc. in a case that johnweeks mentioned.
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
You are not telling us if you are looking at the sum of the infinite series. If so, take a look at the SumSeries operation that's new in IP7.

A.G.
WaveMetrics, Inc.
Thanks for the help! I got my infinite series working well. I have a follow up question. I'm trying to get a matrix where each value is a function of x and y. So I have a wave of x values and a wave of y values and I need a matrix of velocity magnitude at each x and y value as calculated by a velocity function. The formula I'm using for velocity is a summation using a for loop, as y'all suggested previously.

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.


VelocityProfile.ipf
eapurcel wrote:

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.


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 ...

velocityP[][] = ... positionsX[p] ... positionsY[q]


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