3

Minimal example

fun = (r /.NDSolve[
    {D[r[t], t] == -I (PauliMatrix[1].r[t]-r[t].PauliMatrix[1]), 
     r[0] == {{1, 0}, {0, 0}}},
     r, 
     {t, 0, 2}][[1]])

fun is the solution of a differential equation of matrices as a InterpolatingFunction. It has Output dimensions {2,2}, i.e. for each t it returns a two by two matrix, as it should.

If apply FunctionInterpolation to it, the Output dimensions change to {2}, i.e.

FunctionInterpolation[fun[t],{t,0,2}]

returns an InterpolatingFunction which returns a vector of length 2.

Context

I want to multiply the output fun[t] by a probability-distribution e.g. PDF[NormalDistribution[1,0.1],t] and Integrate over t around 1. To achieve this I thought, inspired by the tutorial on Approximate Functions and Interpolation, I could do something like this:

NIntegrate[
FunctionInterpolation[PDF[NormalDistribution[1, 0.1], t]*fun[t], {t, 0, 2}],
{t,0.8,1.2}]

Which fails due to non-numerical values for all sampling points in the region with boundaries... which might but maybe not has something to do with the problem above.

I'd appreciate any comments,

Cheers

AndreasP
  • 598
  • 4
  • 10
  • Note that fun already is a function interpolation. It doesn't seem that FunctionInterpolation should even be considered in this case. – Michael E2 Dec 14 '16 at 14:58
  • Hey @MichaelE2, thanks for your comment. In the link above, FunctionInterpolation is used as FunctionInterpolation[x+sin[x^2],{x,0,1}] where sin is an InterpolatingFunction of Sin, i.e. it is used to combine normal functions (Plus,Power) with an InterpolatingFunction which is what I want to do ultimately. The minimal example might as well include a +t to mirror the example better yet it has the same problem. Cheers

    Edit: The second link you provided might help me a lot later, thanks!

    – AndreasP Dec 14 '16 at 15:06
  • You may want to try other tacks like: Evaluating both as "fields" over the range. Separating the Integral into Real and Imaginary and/or separating it by "Parts" as two separate NIntegrate or N[Integrate[]] Functions. – Ramble Dec 14 '16 at 15:40

1 Answers1

2

Using NDSolve is mentioned in my answer to NIntegrate over a list of functions:

{fun, expectation} = {r, int} /. First@NDSolve[
     {D[r[t], t] == -I (PauliMatrix[1].r[t] - r[t].PauliMatrix[1]), 
      r[0] == {{1, 0}, {0, 0}},
      int'[t] == PDF[NormalDistribution[1, 0.1], t]*r[t], 
      int[0] == {{0, 0}, {0, 0}}},
     {r, int}, {t, 0, 2}];
expectation[2]
(*  {{0.296047 + 0. I, 0. + 0.445646 I}, {0. - 0.445646 I, 0.703953 + 0. I}}  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747