6 kyu

Euler method for numerical integration

198stok

Description:

In this Kata, we use the Euler method for integrating a function (see wiki).

Remember that integrating a function basically means 'calculating the area under a curve'. One way to approximate the area is to chop it up into rectangles (whose area is just height * width) and sum them (see this other wiki page which has a nice gif illustrating this point). We are going to do just this.

Let y = 5 + 2 * x + 3 * x^2.

Write a function

def euler(stop, step_size)

that calculates the integral of y between x = 0 and x = stop. For the sake of simplicity, stop > 0.

As the example test shows, the code will be verified by using a step_size of 0.0001, then rounding the output to the nearest integer.

Algorithms

More By Author:

Check out these other kata created by stok

Stats:

CreatedJan 16, 2017
PublishedJan 16, 2017
Warriors Trained378
Total Skips17
Total Code Submissions664
Total Times Completed198
Python Completions198
Total Stars13
% of votes with a positive feedback rating84% of 70
Total "Very Satisfied" Votes48
Total "Somewhat Satisfied" Votes22
Total "Not Satisfied" Votes0
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • stok Avatar
  • raulbc777 Avatar
  • mmalkavian Avatar
Ad