isdsucph / isds2021

Introduction to Social Data Science 2021 - a summer school course https://isdsucph.github.io/isds2021/
MIT License
22 stars 37 forks source link

Problem 0.3.4 #10

Closed lassearpe closed 3 years ago

lassearpe commented 3 years ago

Hello everyone,

I am totally at odds trying to figure out problem 0.3.4.

I have two issues.

  1. How do I enter the natural log input calculation in python?

image

  1. How exactly should one create the sum-"loop"?

image

(And how does this bring a "partial" sum to add to the total value in each step of the loop?)

Any help appreciated, Lasse

joachimkrasmussen commented 3 years ago

Hi Lasse

Here, you want to write a function on the following form:

def my_fun(x, k_max):
    my_sum = 0
    for k in range(k_max + 1):
        my_partial_sum = (k+x)**2
        my_sum = my_sum + my_partial_sum
    return my_sum

What I have used here is neither the right function nor the most elegant solution to the problem. However, it hopefully helps you understand how to (i) create a sum of a complicated expression (here a sum of (k+x)**2 with k going from 0 to k_max and x being some input of your choice), and (ii) create a sum-"loop".

Was this helpful?

Best, Joachim

lassearpe commented 3 years ago

Hi Joachim

Yeah, thanks a lot. I still find the mathmatics part a bit difficult to understand, but I will try to solve the problem to the best of my ability.

Best, Lasse