Question: Numerical integration of procedures

Hi,

somehow Maple does not integrate a procedure in the correct way. And I don't know why. Could you please help?

This procedure creates a matrix of a special form

P:=proc(n,k,A,d,Lambda)

local p,i,j,m,off,eps:  

if n<6 then print("n greater 6"): return: end if:  

if (n mod 4)<>2 then print("n has to be n (mod 4) = 2 "): return: end if:  

eps:=proc(m,A,Lambda,k) (k+m*Lambda*2)^2+A/2 end proc:  

p:=Matrix(n,shape=symmetric):  

off:=(n-2)/4:  

for i from 1 to n do  

for j from 1 to i do    

m:=trunc((i-1)/2)-off: #print("m",m):    

if i=j then      p[i,j]:=eps(m,A,Lambda,k)*(-1)^(i+1):    

elif i=j+1 then     

 if type(i,even) then p[i,j]:=-d end if:    

elif i=j+2 then      p[i,j]:=A/4*(-1)^(i+1):    

else      p[i,j]:=0:    

end if:   

end do:  

end do:

p;

end proc:

The next procedure calculates eigenvalues and add them

lambdak:=proc(k,n,A,d,Lambda) uses LinearAlgebra:

local lambda,lambda0,intw:

lambda:=Eigenvalues(P(n,k,A,d,Lambda)):  

lambda0:=Eigenvalues(P(n,k,A,0,Lambda)):  

intw:=add((abs(lambda[j])-abs(lambda0[j])),j=1..Dimension(lambda)/2);

end proc:

The next procedure integrates the last procedure over k

intk:=proc(d,n,A,Lambda)

local k,l:

evalf(Int('lambdak(k,n,A,d,Lambda)',k=0.0..1.0));

end proc:

Then we evaluate it

intk(2.,14,1.,1.);

But this result is wrong which can you see from the plot of the function.

plot('lambdak(k,14,1.,2.,1)', k= 0...1);

Thank you for your help.

Download EvalfInt.mw

Please Wait...