How to numerically calculate value of complex function given derivative of this function in Haskell?

StackOverflow https://stackoverflow.com/questions/17058512

Question

Given:

  1. Haskell
  2. Complex-valued function df/dz defined on complex plane U (let's say z is a Complex Double).
  3. Point z1 from the U on which df/dz is defined.

Question:

How to get value of function f(z) for which df/dz is a derivative, in point z1? I. e. how to restore value of original function given only it's derivative, assuming complex plane?


This question is somewhat related to my previous question about calculating integrals of complex functions, but they are about different things. Here I am interested not in calculating some scalar value, but in finding the origin function given it's derivative. It's essentially calculating the indefinite integral of this derivative.

Était-ce utile?

La solution

(Runge–Kutta in Haskell)

You can use some numeric solver like Runge-Kutta

-- define 4th order Runge-Kutta map (RK4) 
rk4 :: Floating a => (a -> a) -> a -> a -> a
rk4 f h x = x + (1/6) * (k1 + 2*k2 + 2*k3 + k4)
            where k1 = h * f (x)
                  k2 = h * f (x + 0.5*k1)
                  k3 = h * f (x + 0.5*k2)
                  k4 = h * f (x + k3)

in that case function signature is Floating but you can use RealFloat instead (you can use runge-kutta in complex).

Complete example:

Prelude> import Data.Complex
Prelude Data.Complex> let rk4 f h x = x + (1/6) * (k1 + 2*k2 + 2*k3 + k4) where {k1 = h * f(x);k2 = h * f (x + 0.5*k1);k3 = h * f (x + 0.5*k2);k4 = h * f (x + k3)}
Prelude Data.Complex> let f z = 2 * z
Prelude Data.Complex> rk4 f (0.1 :+ 0.2) (0.3 :+ 1.2)
(-0.2334199999999999) :+ 1.4925599999999999
Prelude Data.Complex>

On the other hand, @leftaroundabout suggest extend that behavior to VectorSpace (great! of course! :D )

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top