numworks / epsilon

Modern graphing calculator operating system.
https://www.numworks.com/resources/engineering/software/
1.75k stars 463 forks source link

Function for calculating sum of a sequence with a step less than one #1199

Open nick-gable opened 4 years ago

nick-gable commented 4 years ago

Hey all, I created an issue about this about a year ago, but I didn't form it in the best way so I decided now would be a good time to bring it up again.

Calculating the sum of a sequence with a step less than one

The gist of what I am asking for is the equivalent function to the "sum seq" summation function on Ti calculators. Basically, the function allows you to add all of the values of a particular function within a range, and use any step size you like. As a calculus student, this function is incredibly useful when calculating Riemann sums, which require you to add together several values of a function. Often times, the Riemann sum will be finite enough that it requires adding together values of a function with x values that are not integers (ex. calculating L6 from 0 to 3 of a function would require taking the function values at x = 0, 0.5, 1, 1.5, 2, 2.5 and adding them together). Although the sums can be calculated by creating a function and then typing ex 1/2(f(0)+f(0.5)+f(1)...), this is tedious and inefficient, especially considering the ease that it can be implemented programmatically (and has been done before on Ti and Casio devices).

What I've tried

I wrote a python script that operated in a manner similar to that of the sum seq function on Ti calculators. (https://workshop.numworks.com/python/ngable1995/sum) The script works fine, but relying on it is not always easy for various reasons. First of all, the syntax can be a little picky (since you have to write functions into the terminal directly), and any syntax errors mean you have to restart using the script. Additionally, relying on scripts in general is not always super reliable since technically testing proctors could require students to turn on exam mode, which would erase the script and prevent its use on the applicable test (most likely AP Calculus). (The script also unexplainably returns incorrect results; I couldn't determine why but believe it is a result of some sort of issue with python's calculation of sine and cosine values, but that's just a guess)

My solution

I think the most practical solution for this problem is to implement a function similar to sum seq directly into the toolbox for use in the calculation app. Since it doesn't have a written syntax like regular summations, implementing it would be similar to the differentiation function; namely, something a long the lines of sumseq(f(x),x,a,b,s) with a and b being the start and end values and s being the step size.

alexeyneu commented 4 years ago

looks like it couuld be done with
)

RubenNumworks commented 4 years ago

The summation notation in mathematics has a lower and an upper bound but no step. There might exist some local notations which include a step but there would be neither generic nor standard at all.

I agree though that it may be convenient in some specific cases to be able to set the step of a sum. However, isn't it simpler to write sum(f(a+step*n), n, 0, N) than making notations more complicated?

Related to #829 and #830 for history.