I'm working on some calculus functions in swift. The main barrier I have to all of them is taking some kind of user input system and being able to use that in the function. For example, if I can translate what the user inputs into a swift acceptable mathematical expression then I can do all the calculus based things I need with pretty simple functions like:
Derivitive:
func derivativeOf(fn: (Double)->Double, atX x: Double) -> Double {
let h = 0.0000001
return (fn(x + h) - fn(x))/h
}
Limit
func limit(fn: (Double)->Double, atX x: Double) -> Double {
let modifier = 0.0000001
return (fn(x + modifier))
}
Ect..
What strategy of user input can I do to make swift be clear on the Double to Double functions my calculus functions need? How do I translate trig functions, constants, exponents, ect. well?