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?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Much better than mine
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.