
function P=Pintegrated(xtip,ztip,length,dip,lam,mu,k)
a=dip;
g=lam+2*mu;
L=lam;
R=sqrt(xtip^2+ztip^2);

P(1,1)=1/(4*g*k)*(i*(5*g - 3*L - 4*mu)*cos(a + i*k*R*sin(a)) + (g - 3*L - 4*mu)*(k*R*cos(2*a + i*k*R*sin(a)) - ...
   i*cos(3*a + i*k*R*sin(a))) + k*(-g + 3*L + 4*mu)*R*cosh(k*R*sin(a)))/exp(i*k*R*cos(a));
P(1,2)=1/(4*g*k)*((-7*g + 9*L + 12*mu)*sin(a + i*k*R*sin(a)) + (g - 3*L - 4*mu)*(i*k*R*sin(2*a + i*k*R*sin(a)) + ... 
   sin(3*a + i*k*R*sin(a))) + k*(g - 3*L - 4*mu)*R*sinh(k*R*sin(a)))/exp(i*k*R*cos(a));
P(1,3)=1/(4*g*k^2*mu)*((-7*g + 6*L + 9*mu)*sin(a + i*k*R*sin(a)) + (g - 2*L - 3*mu)*(i*k*R*sin(2*a + i*k*R*sin(a)) + ... 
   sin(3*a + i*k*R*sin(a))) + k*(g - 2*L - 3*mu)*R*sinh(k*R*sin(a)))/exp(i*k*R*cos(a));
P(1,4)=((L + mu)*sin(a)*(k*R*sin(a + i*k*R*sin(a)) - i*sin(2*a + i*k*R*sin(a))))/(exp(i*k*R*cos(a))*2*g*k^2*mu);
P(2,1)=1/(4*g^2*k)*((7*g*L - 3*(L + 2*mu)*(3*L + 2*mu))*sin(a + i*k*R*sin(a)) + (-g*L + (L + 2*mu)*(3*L + 2*mu))* ...
     (i*k*R*sin(2*a + i*k*R*sin(a)) + sin(3*a + i*k*R*sin(a))) + k*(-g*L + (L + 2*mu)*(3*L + 2*mu))*R*sinh(k*R*sin(a)))/ ...
     exp(i*k*R*cos(a));
P(2,2)=(i*(5*g + L)*cos(a + i*k*R*sin(a)) + (g + L)*(k*R*cos(2*a + i*k*R*sin(a)) - i*cos(3*a + i*k*R*sin(a))) - ... 
   k*(g + L)*R*cosh(k*R*sin(a)))/(exp(i*k*R*cos(a))*4*g*k);
P(2,3)=(i*(L + mu)*sin(a)*(i*k*R*sin(a + i*k*R*sin(a)) + sin(2*a + i*k*R*sin(a))))/(exp(i*k*R*cos(a))*2*g*k^2*mu);
P(2,4)=1/(4*g^2*k^2*mu)*(-(7*g*mu + 3*L*(L + 2*mu))*sin(a + i*k*R*sin(a)) + (L^2 + g*mu + 2*L*mu)* ...
   (i*k*R*sin(2*a + i*k*R*sin(a)) + sin(3*a + i*k*R*sin(a))) + k*(L^2 + g*mu + 2*L*mu)*R*sinh(k*R*sin(a)))/exp(i*k*R*cos(a));
P(3,1)=1/g^2*(mu*(L + mu)*((-7*g + 6*L + 12*mu)*sin(a + i*k*R*sin(a)) + (g - 2*L - 4*mu)*(i*k*R*sin(2*a + i*k*R*sin(a)) + ...
   sin(3*a + i*k*R*sin(a))) + k*(g - 2*(L + 2*mu))*R*sinh(k*R*sin(a))))/exp(i*k*R*cos(a));
P(3,2)=(2*mu*(L + mu)*sin(a)*(k*R*sin(a + i*k*R*sin(a)) - i*sin(2*a + i*k*R*sin(a))))/(exp(i*k*R*cos(a))*g);
P(3,3)=1/(4*g*k)*(i*(5*g - 3*L - 4*mu)*cos(a + i*k*R*sin(a)) + (g - 3*L - 4*mu)*(k*R*cos(2*a + i*k*R*sin(a)) - ... 
   i*cos(3*a + i*k*R*sin(a))) + k*(-g + 3*L + 4*mu)*R*cosh(k*R*sin(a)))/exp(i*k*R*cos(a));
P(3,4)=1/(4*g^2*k)*((-7*g*L + 3*(L + 2*mu)*(3*L + 2*mu))*sin(a + i*k*R*sin(a)) + (g*L - (L + 2*mu)*(3*L + 2*mu))* ...
     (i*k*R*sin(2*a + i*k*R*sin(a)) + sin(3*a + i*k*R*sin(a))) + k*(g*L - (L + 2*mu)*(3*L + 2*mu))*R*sinh(k*R*sin(a)))/ ...
     exp(i*k*R*cos(a));
P(4,1)=(2*i*mu*(L + mu)*sin(a)*(i*k*R*sin(a + i*k*R*sin(a)) + sin(2*a + i*k*R*sin(a))))/(exp(i*k*R*cos(a))*g);
P(4,2)=(mu*(L + mu)*(-3*sin(a + i*k*R*sin(a)) + i*k*R*sin(2*a + i*k*R*sin(a)) + sin(3*a + i*k*R*sin(a)) + k*R*sinh(k*R*sin(a))))/ ...
   (exp(i*k*R*cos(a))*g);
P(4,3)=1/(4*g*k)*((7*g - 3*(3*L + 4*mu))*sin(a + i*k*R*sin(a)) + (-g + 3*L + 4*mu)*(i*k*R*sin(2*a + i*k*R*sin(a)) + ... 
   sin(3*a + i*k*R*sin(a))) + k*(-g + 3*L + 4*mu)*R*sinh(k*R*sin(a)))/exp(i*k*R*cos(a));
P(4,4)=(i*(5*g + L)*cos(a + i*k*R*sin(a)) + (g + L)*(k*R*cos(2*a + i*k*R*sin(a)) - i*cos(3*a + i*k*R*sin(a))) - ... 
   k*(g + L)*R*cosh(k*R*sin(a)))/(exp(i*k*R*cos(a))*4*g*k);



R=sqrt((xtip+length*cos(a))^2+(ztip+length*sin(a))^2);
P2(1,1)=1/(4*g*k)*(i*(5*g - 3*L - 4*mu)*cos(a + i*k*R*sin(a)) + (g - 3*L - 4*mu)*(k*R*cos(2*a + i*k*R*sin(a)) - ...
   i*cos(3*a + i*k*R*sin(a))) + k*(-g + 3*L + 4*mu)*R*cosh(k*R*sin(a)))/exp(i*k*R*cos(a));
P2(1,2)=1/(4*g*k)*((-7*g + 9*L + 12*mu)*sin(a + i*k*R*sin(a)) + (g - 3*L - 4*mu)*(i*k*R*sin(2*a + i*k*R*sin(a)) + ... 
   sin(3*a + i*k*R*sin(a))) + k*(g - 3*L - 4*mu)*R*sinh(k*R*sin(a)))/exp(i*k*R*cos(a));
P2(1,3)=1/(4*g*k^2*mu)*((-7*g + 6*L + 9*mu)*sin(a + i*k*R*sin(a)) + (g - 2*L - 3*mu)*(i*k*R*sin(2*a + i*k*R*sin(a)) + ... 
   sin(3*a + i*k*R*sin(a))) + k*(g - 2*L - 3*mu)*R*sinh(k*R*sin(a)))/exp(i*k*R*cos(a));
P2(1,4)=((L + mu)*sin(a)*(k*R*sin(a + i*k*R*sin(a)) - i*sin(2*a + i*k*R*sin(a))))/(exp(i*k*R*cos(a))*2*g*k^2*mu);
P2(2,1)=1/(4*g^2*k)*((7*g*L - 3*(L + 2*mu)*(3*L + 2*mu))*sin(a + i*k*R*sin(a)) + (-g*L + (L + 2*mu)*(3*L + 2*mu))* ...
     (i*k*R*sin(2*a + i*k*R*sin(a)) + sin(3*a + i*k*R*sin(a))) + k*(-g*L + (L + 2*mu)*(3*L + 2*mu))*R*sinh(k*R*sin(a)))/ ...
     exp(i*k*R*cos(a));
P2(2,2)=(i*(5*g + L)*cos(a + i*k*R*sin(a)) + (g + L)*(k*R*cos(2*a + i*k*R*sin(a)) - i*cos(3*a + i*k*R*sin(a))) - ... 
   k*(g + L)*R*cosh(k*R*sin(a)))/(exp(i*k*R*cos(a))*4*g*k);
P2(2,3)=(i*(L + mu)*sin(a)*(i*k*R*sin(a + i*k*R*sin(a)) + sin(2*a + i*k*R*sin(a))))/(exp(i*k*R*cos(a))*2*g*k^2*mu);
P2(2,4)=1/(4*g^2*k^2*mu)*(-(7*g*mu + 3*L*(L + 2*mu))*sin(a + i*k*R*sin(a)) + (L^2 + g*mu + 2*L*mu)* ...
   (i*k*R*sin(2*a + i*k*R*sin(a)) + sin(3*a + i*k*R*sin(a))) + k*(L^2 + g*mu + 2*L*mu)*R*sinh(k*R*sin(a)))/exp(i*k*R*cos(a));
P2(3,1)=1/g^2*(mu*(L + mu)*((-7*g + 6*L + 12*mu)*sin(a + i*k*R*sin(a)) + (g - 2*L - 4*mu)*(i*k*R*sin(2*a + i*k*R*sin(a)) + ...
   sin(3*a + i*k*R*sin(a))) + k*(g - 2*(L + 2*mu))*R*sinh(k*R*sin(a))))/exp(i*k*R*cos(a));
P2(3,2)=(2*mu*(L + mu)*sin(a)*(k*R*sin(a + i*k*R*sin(a)) - i*sin(2*a + i*k*R*sin(a))))/(exp(i*k*R*cos(a))*g);
P2(3,3)=1/(4*g*k)*(i*(5*g - 3*L - 4*mu)*cos(a + i*k*R*sin(a)) + (g - 3*L - 4*mu)*(k*R*cos(2*a + i*k*R*sin(a)) - ... 
   i*cos(3*a + i*k*R*sin(a))) + k*(-g + 3*L + 4*mu)*R*cosh(k*R*sin(a)))/exp(i*k*R*cos(a));
P2(3,4)=1/(4*g^2*k)*((-7*g*L + 3*(L + 2*mu)*(3*L + 2*mu))*sin(a + i*k*R*sin(a)) + (g*L - (L + 2*mu)*(3*L + 2*mu))* ...
     (i*k*R*sin(2*a + i*k*R*sin(a)) + sin(3*a + i*k*R*sin(a))) + k*(g*L - (L + 2*mu)*(3*L + 2*mu))*R*sinh(k*R*sin(a)))/ ...
     exp(i*k*R*cos(a));
P2(4,1)=(2*i*mu*(L + mu)*sin(a)*(i*k*R*sin(a + i*k*R*sin(a)) + sin(2*a + i*k*R*sin(a))))/(exp(i*k*R*cos(a))*g);
P2(4,2)=(mu*(L + mu)*(-3*sin(a + i*k*R*sin(a)) + i*k*R*sin(2*a + i*k*R*sin(a)) + sin(3*a + i*k*R*sin(a)) + k*R*sinh(k*R*sin(a))))/ ...
   (exp(i*k*R*cos(a))*g);
P2(4,3)=1/(4*g*k)*((7*g - 3*(3*L + 4*mu))*sin(a + i*k*R*sin(a)) + (-g + 3*L + 4*mu)*(i*k*R*sin(2*a + i*k*R*sin(a)) + ... 
   sin(3*a + i*k*R*sin(a))) + k*(-g + 3*L + 4*mu)*R*sinh(k*R*sin(a)))/exp(i*k*R*cos(a));
P2(4,4)=(i*(5*g + L)*cos(a + i*k*R*sin(a)) + (g + L)*(k*R*cos(2*a + i*k*R*sin(a)) - i*cos(3*a + i*k*R*sin(a))) - ... 
   k*(g + L)*R*cosh(k*R*sin(a)))/(exp(i*k*R*cos(a))*4*g*k);


P=P2-P;

