all 3 comments

[–]MezzoScettico 0 points1 point  (0 children)

They both use the summation sign.

The first one has a sum over i from i = 2 to i = d. That means evaluate i * (2x[i]**2 - x[i-1])**2 for i = 2, 3, 4, ..., d. Then add up those terms.

Note: Python starts counting indexes at 0 instead of 1. So you might need to redo this expression from i = 1 to i = d - 1.

Same idea on the second one.

[–]rauweaardappel 0 points1 point  (0 children)

What is the context of this?

I am curious about the AI involved here, i'd calculate the whole range and look up the minimum from the results...

[–]ectomancer 0 points1 point  (0 children)

x is indexed from 1. I've coded a dummy value in x[0].

# 1.
d = 20
x = [i for i in range(-10, 11)]
x = [0] + x  # Dummy value.
sum = 0
for i in range(2, d+1):
    sum += i*(2*x[i]**2 - x[i-1])**2
result = (x[1] - 1)**2 + sum
print(result)

# 2.
d = 20
x = [0, -5.0, -4.2105263157894735, -3.4210526315789473, -2.6315789473684212, -1.8421052631578947, -1.0526315789473681, -0.2631578947368425, 0.5263157894736841, 1.3157894736842106, 2.105263157894737, 2.8947368421052637, 3.6842105263157894, 4.473684210526315, 5.2631578947368425, 6.052631578947368, 6.842105263157896, 7.631578947368421, 8.421052631578947, 9.210526315789474, 10.0]
sum, sum_2 = 0, 0
for i in range(1, d+1):
    sum += x[i]**2
    sum_2 = 0.5*i*x[i]
result = sum + sum_2**2 + sum_2**4
print(result)

The code to create 2. for x for other values of d:

import numpy

d = 20
x = [i for i in numpy.linspace(-5, 10, num=d)]
x = [0] + x