Last active
August 29, 2015 14:21
-
-
Save harrisonweinerman/b2c60453708240d941ea to your computer and use it in GitHub Desktop.
Swift Riemann Sum Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This code works fine in a Swift playground. | |
let startingX = 0.0 | |
let finishingX = 2.0 | |
//make this smaller for more accuracy but slower calculation times | |
let increment = 0.1 | |
var area = 0.0 | |
func fOfX(x : Double) -> Double{ | |
//write your function here | |
return 8 - pow(x, 2) | |
} | |
for var i = startingX; i < finishingX; i += increment { | |
area += increment * fOfX(i) | |
} | |
println("Area is \(area).") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment