0

Starting from the vector Psi_0 I define the propagated vector as Psi (t) = exp{-iHt} Psi_0, where H is the Adjacency matrix (but I think it is irrelevant to my problem here). I need to calculate

1/tau * int^tau_0 |<j|psi(t)>|^2 dt

I tried to do this in the following way but it doesn't work

psi_0 = diag(eye(N))/N;
Psi_t = zeros(N);

Psi_sqared = @(t) (expm(1j*A*t)*psi_0).*(expm(-1j*A*t)*psi_0);

c_tqw = integral(Psi_sqared, 0, 10000)/10000;

The error is the following

Error using  * 
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the
second matrix. To perform elementwise multiplication, use '.*'.

Error in centrality_measure>@(t)(expm(1j*A*t)*psi_0).*(expm(-1j*A*t)*psi_0)

Error in integralCalc/iterateScalarValued (line 314)
                fx = FUN(t);

Error in integralCalc/vadapt (line 132)
            [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);

Error in integralCalc (line 75)
        [q,errbnd] = vadapt(@AtoBInvTransform,interval);

Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);

Error in centrality_measure (line 75)
c_tqw = integral(Psi_sqared, 0, 10000)/10000;

Any suggestion to avoid this error?

Vladimir Vagaytsev
  • 2,871
  • 9
  • 33
  • 36
raskolnikov
  • 235
  • 1
  • 6
  • 1
    Firstly make sure you understand the difference between the `.*` and `*` operators. Secondly you're not passing in `t` to your anonymous function when you call it, nor are you defining (or showing us) what `A` is. I would suggest you write a regular function (rather than use an anonymous function handle) since they're easier to debug, add some breakpoints and then step through the code line by line to hunt down your problems.Good luck! – Justin Nov 12 '18 at 10:07
  • A is the adjacency matrix of a Graph with 20 nodes. N is the number of nodes. So i think that the product expm(1j*A*time)*psi_0 is well defined. I've built a function as you suggested but the error is the same when i call it: Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'. Nevertheless, if I call it as Psi_squared(10) it works well, if i call it inside the computation of the integral it gives me the error stated above. – raskolnikov Nov 12 '18 at 13:47
  • The error should be the same, I was suggesting it would be easier to debug! Using the function, add a breakpoint and then inspect `t` when the function gets called by the integrator. However, for a chance at getting the answer you really need you should post some code we can actually run. See [mcve] – Justin Nov 12 '18 at 16:26
  • I find out what was the problem: there is an option in the matlab function "integral" that allow to give an array as an input and to obtain an array as an output. Without this option I think that matlab interpret the array of function in a wrong way. I solved with `c_ctqw = integral(@(t) psi_t_squared(t,A,N), 0, infin,'ArrayValued',1)/infin;`, where I used the option 'ArrayValued' as true (infin is just a parameter). Thanks for the patience, Justin! – raskolnikov Nov 13 '18 at 08:23

0 Answers0