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
|
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstdlib>
using namespace std;
void jac_inv (double jac[3][3],int m);
void update_delx (double j_inv[3][3],double f[3],int m);
double j_inv[3][3],delx[3],x[3],f[3];
int m,a,b,c,i,n=3,j;
main()
{
double r1,r2,is,id,v0,v1,v2,vt,g1,g2,jac[3][3],t=0.0,nor=0.0,norm,delt,eph,expv2;
double T=1.0/50.0;
delt=T/100;
eph = 1.0e-6;
r1 = 1.0e3;
r2 = 1.0e3;
is = 1.0e-14;
vt = 26.0e-3;
v0 = 5.0;
x[0] = 0.0;
x[1] = 0.0;
x[2] = 0.0e-3;
update:
v1 = x[0];
v2 = x[1];
id = x[2];
expv2 = exp(v2/vt);
g1=1.0/r1;
g2=1.0/r2;
v1=v0*sin(2*3.14*50*t);
// create the jacobian matrix
jac[0][0] = g1;
jac[0][1] = -g1;
jac[0][2] = 1.0;
jac[1][0] = -g1;
jac[1][1] = g1 + g2 + (is/vt)*expv2;
jac[1][2] = 0.0; v1 = x[0];
jac[2][0] = 1.0;
jac[2][1] = 0.0;
jac[2][2] = 0.0;
//compute f-minus matrix
f[0] = id+g1*(v1-v2);
f[1] = g1*(v2-v1) + g2*v2 + is*(expv2 - 1.0);
f[2] = v1 - v0;
for(a=0;a<3;a++)
{
f[a]=-1.0*f[a];
}
//check norm
for(b=0;b<3;b++)
{
nor= f[b]*f[b] + nor;
}
norm=sqrt(nor);
if (norm < eph)
{
cout << v2 << " " << -1.0*id << "\n";
t=t+delt;
if (t>T)
exit;
else
goto update;
}
jac_inv(jac,3);
update_delx(j_inv,f,3);
goto update;
}
void jac_inv(int (*jac)[3], int m)
{
double determinant=0.0;
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
j_inv[i][j]=jac[i][j];
}
}
for(i=0;i<m;i++)
{
determinant = determinant + (j_inv[0][i]*(j_inv[1][(i+1)%n]*j_inv[2][(i+2)%n] - j_inv[1][(i+2)%n]*j_inv[2][(i+1)%n]));
}
i=0;
j=0;
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
j_inv[i][j]=(((j_inv[(i+1)%n][(j+1)%n] * j_inv[(i+2)%n][(j+2)%n]) - (j_inv[(i+1)%n][(j+2)%n]*j_inv[(i+2)%n][(j+1)%n]))/ determinant);
}
}
}
void update_delx(int (*j_inv)[3],int *f,int m)
{
delx[0]=0.0;
delx[1]=0.0;
delx[2]=0.0;
double k=0.6;
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
delx[i]=delx[i]+j_inv[i][j]*f[j];
}
for(c=0;c<3;c++)
{
x[c]=x[c]+k*delx[c];
}
}
}
|