2

I am beginner with gnuplot and I am trying to plot the following function with gnuplot:

f(x) = sum[i=0:x](Pi[j=0:i](x+j-3))

where by Pi I mean the product operator:

Pi[j=0:i](x+j-3) = (x+0-3)*(x+1-3)...(x+i-3)

How can I write the gnuplot script for the Pi part?

Miguel
  • 7,497
  • 2
  • 27
  • 46
Homer
  • 97
  • 1
  • 8

2 Answers2

3

if I didn't made mistakes you could use a recursive function:

prod(x,n,m) = (n<0) ? 1 : (x+n+m) * prod(x,n-1,m)
f(x) = sum[i=0:int(x)](prod(x,i,-3))
plot [0:3] f(x)

enter image description here

bibi
  • 3,671
  • 5
  • 34
  • 50
2

You can follow the recipe in this answer to use external functions, in this case Python. Create the external file function.py:

import sys
x=float(sys.argv[1])
i=int(sys.argv[2])

p = 1
for j in range(0,i+1):
    p *= x + j - 3

print p

Now in gnuplot you can define the following product and sum functions:

prod(x,i) = real(system(sprintf("python function.py %g %i", x, i)))

f(x) = sum[i=0:int(x)](prod(x,i))

plot[0:3] f(x)

enter image description here

Note that x needs to be integer to be used to define the limits of the summation. Also note that calling external functions is quite slow.

Community
  • 1
  • 1
Miguel
  • 7,497
  • 2
  • 27
  • 46