Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <complex.h>
  5.  
  6. #define SIZE 2
  7. #define wmax 2
  8. #define wmin 0.001
  9. #define rhor 2.0001
  10. #define rinf 1000.
  11. #define eps 1
  12.  
  13.  
  14. double r;
  15. double complex X[SIZE],X1[SIZE];
  16. double rh,ri,h,wi,wf,e,hw;
  17. int    finesse,i,j,k,kl,l,n;
  18. // DE system to integrate (n=2)
  19.       void F(double r, double w, int l, double f,double e, double complex x[], double complex xp[]) {
  20.         xp[0] = x[1];
  21.         xp[1] = ((-(2-r)*(2*r*r+l*(l+1)*r*r*r + l*(l+1)*e) - r*r*r*r*r*r*w*w)*x[0]+2*(2-r)*r*r*r*x[1])/(r*r*r*r*(r-2)*(r-2));
  22.       }
  23. //Integrate first order DE sytem from x to x+h using Runge-Kutta
  24.       void RK4n(int n, double r, double w, int l, double f,double e, double complex x[], double h, double complex x1[]) {
  25.         double complex c1[SIZE],c2[SIZE],c3[SIZE],c4[SIZE],xx[SIZE];
  26.         double h2;
  27.         int i;
  28.         F(r,w,l,f,e,x,c1);
  29.         h2=h/2.0;
  30.         for (i=0; i<n; i++) xx[i]=x[i]+h2*c1[i];
  31.         F(r+h2,w,l,f,e,xx,c2);
  32.         for (i=0; i<n; i++) xx[i]=x[i]+h2*c2[i];
  33.         F(r+h2,w,l,f,e,xx,c3);
  34.         for (i=0; i<n; i++) xx[i]=x[i]+h*c3[i];
  35.         F(r+h,w,l,f,e,xx,c4);
  36.         for (i=0; i<n; i++)
  37.           x1[i]=x[i]+h*(c1[i]+2.0*c2[i]+2.0*c3[i]+c4[i])/6.0;
  38.       }
  39. int main(){
  40.  
  41. double w,f;
  42. double complex dXi;
  43. n=2;           // size of DE system
  44. e=eps;          //value of epsilon
  45. rh = rhor;      //starting r
  46. ri = rinf;      //ending r
  47. wi=wmin;        // starting w
  48. wf=wmax;        // ending w
  49. kl=25;         // number of calculated points
  50. finesse=20;
  51. h=0.1;
  52. r=rh;
  53. w=wi;
  54. f=(1-2/r);         //f(r) function of the metric
  55. dXi=(-I*w)/(1-2/rh);
  56. double complex tr2;
  57. l=0;
  58.  
  59. X[0]=1;    // starting X values
  60. X[1]=dXi;  // starting X' values
  61.  
  62. FILE *fpout;
  63. fpout = fopen("Transe0l0c.dat","w");
  64. // integration loop
  65. while (w<wmax){
  66.     while(r<ri){
  67.         RK4n(n,r,w,l,f,e,X,h,X1);
  68.         for (j=0; j<n; j++) X[i]=X1[i];
  69.         r+=0.1;
  70.         }
  71.     tr2=4/(2+X[0]*conj(X[0])+((1-2/ri)*(1-2/ri)/(w*w))*X[1]*conj(X[1]));
  72.     fprintf(fpout, "%.8lf %.8lf\n",w,creal(tr2));
  73.     w+=0.01;
  74.     X[0]=1;
  75.     X[1]=dXi;
  76.     }
  77.  
  78. fclose(fpout);
  79.  
  80. return (0);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement