Functions in Mathematics and Programming

Here is a simple and somewhat contrived example of how such a function could be defined.Naturally real functions will not be defined like this.Laplace TransformI will not explain what the purpose of the Laplace transform is here, but instead shows you some different possible notation for it as well as give examples of how you would translate this into code.The transform is denoted with the letter ℒ, taking a function f of t as argument and return a function F of s.In Julia code this could be expressed roughly as:ℒ(f) = s -> sum(t -> f(t) * e^(-s*t) * Δt, 0:∞)Or in the longer form:function ℒ(f::Function) function(s) sum(0:∞) do t f(t) * e^(-s*t) * Δt end endendThis is of course different from the mathematical definition, because in code we cannot deal with continuous definition..We are dealing with a discrete version..Instead of an infinitely small dt we have to deal with some sensibly picked Δt.Nor can we deal with an infinitely large range such as 0:∞, but have to pick some practical approximation..The point of showing this code is just to help you understand the principle.If we look at our previous definition of an integral transform, you can deduce that the kernel function, K in the Laplace transform is:Fourier TransformLet us look at some possible ways of defining the Fourier transformusing mathematical notation and code.You can probably tell that our kernel K in this case is:We can then define the Fourier transform in code as:????(f) = ξ -> sum(x -> f(x) * e^(-2π*i*xξ) * Δx, -∞:∞)Or in the longer form:function ????(f::Function) function(ξ) sum(0:∞) do x f(x) * e^(-2π*i*xξ) * Δx end endendFinal RemarksI hope this article helped you to read mathematical notation and get a glimpse of how you can translate mathematics into code.Mathematics has the luxury of expressing theoretical perfect worlds which we cannot deal with in code directly..In code we need to find some discrete numerical representation of the problem..We would have to make approximations to the real mathematical concept.We can e.g..approximate integrals as summing over a range of values with some discrete stepping value..Usually an efficient and accurate code version to implement these transforms will be far more complex that the naive implementations you could create directly from the definitions.. More details

Leave a Reply