1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216

#include <iostream>
#include <cmath>
#include<iomanip>
#include<fstream>
#include<string>
#include<cstdlib>
#include<ctime>
using namespace std;
ofstream fout;
ifstream fin;
string file= "ElectrostaticData";
const long double pi = 3.14159265;
const long double Ke= 8.98756e9;
const long double Q1 = 1.60237657e19;
const long double Q2 = 1.60237657e19;
const long double m = 9.10938291e31;
const long double k = Ke*Q1*Q2/(m);
long double particleMatrix[27][2]={
{1E3 , 2.00E11},
{1E3 , 1.95E11},
{1E3 , 1.90E11},
{1E3 , 1.85E11},
{1E3 , 1.80E11},
{1E3 , 1.75E11},
{1E3 , 1.70E11},
{1E3 , 1.65E11},
{1E3 , 1.60E11},
{1E3 , 1.55E11},
{1E3 , 1.50E11},
{1E3 , 1E12},
{1E3 , 0.5E12},
{1E3 , 0},
{1E3 , 0.5E12},
{1E3 , 1E12},
{1E3 , 1.50E11},
{1E3 , 1.55E11},
{1E3 , 1.60E11},
{1E3 , 1.65E11},
{1E3 , 1.70E11},
{1E3 , 1.75E11},
{1E3 , 1.80E11},
{1E3 , 1.85E11},
{1E3 , 1.90E11},
{1E3 , 1.95E11},
{1E3 , 2.E11}
};
long double thetaArray [27];
void fThetaArrayGen(long double x, long double y);
long double accelGen(long double x, long double y);
long double fTheta(long double x, long double y);
long double distancesMatrix[27][2];
void distancesMatrixGen(long double x, long double y);
long double accelSum(char xy);
long double accelMagArray[27];
void accelMagArrayGen();
long double accelVectorGen(long double a,long double r);
int mainfunc(long double i7);
int main()
{
fout.open(file.c_str());
fout <<"t \tx \ty \tvx \tvy \tax \tay"<<endl;
int counter=0;
for (int i=50; i>=0; i)
{
mainfunc(i*1E9);
}
return 0;
}
int mainfunc(long double i7)
{
srand( time( NULL ) );
long double dt=1E10, dt2=1E10, x=0, y=0, v=3E8, theta1=i7;
long double vx = v*cos(theta1);
long double vy = v*sin(theta1);
distancesMatrixGen(x,y);
fThetaArrayGen(x, y);
long double a;
long double ax=accelSum('x');
long double ay=accelSum('y');
int counter=0;
int breaker=0;
for (long double t=0; ; t+=dt)
{
counter++;
x += (vx*dt)*dt2+(1/2*ax*dt*dt)*dt2*dt2;
y += (vy*dt)*dt2+(1/2*ay*dt*dt)*dt2*dt2;
vx += (ax*dt)*dt2;
vy += (ay*dt)*dt2;
fThetaArrayGen(x,y);
distancesMatrixGen(x,y);
ax=accelSum('x');
ay=accelSum('y');
v=sqrt(vx*vx+vy*vy);
a=sqrt(ax*ax+ay*ay);
if (x>9.995E4&&counter%6000==0)
{
fout <<t<<"\t"<<x<<"\t"<<y<<"\t"<<vx<<"\t"<<vy<<"\t"<<ax<<"\t"<<ay<<endl;
}
if (y>5E11)//edited, pretty much its "if the electron leaves the area I want it in"
{
return 0;
}
if (x>5E3) //if the particle gets to the other side of the field
{
return 1;
}
}///end for loop
}
void fThetaArrayGen(long double x, long double y)///recalc
{
for (int i=0;i<27;i++)
{
thetaArray[i]=fTheta(distancesMatrix[0][i],distancesMatrix[1][i]);
}
}
long double accelGen(long double x, long double y)///called func
{
return k/(x*x+y*y);
}
long double fTheta(long double x, long double y)///called func
{
return atan(y/x);
}
void distancesMatrixGen(long double x, long double y)///recalc
{
for (int i=0; i<27; i++)
{
distancesMatrix[i][0]=xparticleMatrix[i][0];
distancesMatrix[i][1]=yparticleMatrix[i][1];
}
}
long double accelVectorGen(long double a,long double r)
{
if (r>0)
{
return a;
}
else if (r<0)
{
return a;
}
else
{
return 0;
}
}
long double accelSum(char xy)///recalc
{
accelMagArrayGen();
long double sum=0;
if (xy=='x')
{
for (int i=0; i<27; i++)
{
sum+=accelVectorGen(abs(cos(thetaArray[i])*accelMagArray[i]),distancesMatrix[i][0]);
}
}
else if (xy=='y')
{
long double tempSum=0;
for (int i2=0; i2<27; i2++)
{
sum+=accelVectorGen(abs(sin(thetaArray[i2])*accelMagArray[i2]),distancesMatrix[i2][1]);
}
}
return sum;
}
void accelMagArrayGen()///called func
{
long double x;
long double y;
for (int i=0; i<27; i++)
{
x=distancesMatrix[i][0]*1E10;
y=distancesMatrix[i][1]*1E10;
accelMagArray[i]=1E20*accelGen(x,y);
}
}
 