void RelaxOneHamInt(MessRelaxInpPar &RelaxPar, double H,double Qs,double Eta,double Is,double Wid, double *x,double *y) { MessRelaxClcPar *RelaxClc=new MessRelaxClcPar[RelaxPar.NumHam+1]; FormIntArr(RelaxClc,RelaxPar,H, Qs, Eta, Is); my_comp res; double t0,t1; int N=my_real(RelaxClc[1].RelInt[0]); Wid=Wid/2; for (int i=1;i<=x[0];i++) { res=0; for (int k=1;k<=RelaxPar.NumHam;k++) { t1=RelaxClc[k].EndTime;t0=RelaxClc[k-1].EndTime; for (int k1=1;k1<=N;k1++) { my_comp freq=my_comp(-Wid,x[i]-my_real(RelaxClc[k].Freq[k1])); res=res+ RelaxClc[k].RelInt[k1] /freq* ( exp(my_comp( -fabs(Wid*t1),my_imag(freq)*(t1-t0)+x[i]*t0 ))- exp(my_comp(-fabs(Wid*t0),x[i]*t0)) ); } } y[i]=my_real(res); } delete []RelaxClc; };
void GenerateInt(CMatrCl &Ham3,CMatrCl &Rot3Rgt, CMatrCl &Ham1,CMatrCl &Rot1Lft, double t0,double t1,double MaxNorm,my_comp *&res,double &Tstp,int &Nit) { double M=max<double>(MatrNorm(Ham3),MatrNorm(Ham1)); CMatrCl Uni3(4),Uni1(2);Uni3=Uni3*0+1;Uni1=Uni1*0+1; Nit=int((t1-t0)*M/MaxNorm)+1; Tstp=(t1-t0)/Nit; CMatrCl H3=Uni3+Ham3*my_comp(0,Tstp), H1=Uni1-Transpon(Ham1)*my_comp(0,Tstp); delete []res;res=new my_comp[Nit+1];res[0]=Nit; my_comp d3=my_comp(sqrt(2./(3*8)),0),d2=my_comp(sqrt(4./(3*8)),0), d1=my_comp(sqrt(6./(3*8)),0); for (int k=1;k<=Nit;k++) { Rot3Rgt=H3*Rot3Rgt; Rot1Lft=Rot1Lft*H1; res[k]= Rot3Rgt(1,1)*d1*d1*Rot1Lft(1,1)+Rot3Rgt(1,2)*d3*d1*Rot1Lft(2,1)+ Rot3Rgt(2,2)*d3*d3*Rot1Lft(2,2)+Rot3Rgt(2,1)*d3*d1*Rot1Lft(1,2)+ Rot3Rgt(3,3)*d3*d3*Rot1Lft(1,1)+Rot3Rgt(3,4)*d3*d1*Rot1Lft(2,1)+ Rot3Rgt(4,4)*d1*d1*Rot1Lft(2,2)+Rot3Rgt(4,3)*d3*d1*Rot1Lft(1,2)+ Rot3Rgt(2,2)*d2*d2*Rot1Lft(1,1)+Rot3Rgt(2,3)*d2*d2*Rot1Lft(2,1)+ Rot3Rgt(3,3)*d2*d2*Rot1Lft(2,2)+Rot3Rgt(3,2)*d2*d2*Rot1Lft(1,2); } for (k=1;k<=Nit;k++) res[k]/=M_PI; };
void FormAmp(CMatrCl &AmpR1,CMatrCl &AmpL1,CMatrCl &AmpR2,CMatrCl &AmpL2, CMatrCl &AmpR3,CMatrCl &AmpL3) { AmpR1.SetMatr(2,4);AmpR1=AmpR1*0;AmpR2=AmpR1;AmpR3=AmpR1; my_comp d3=my_comp(sqrt(2./(3*8)),0),d2=my_comp(sqrt(4./(3*8)),0), d1=my_comp(sqrt(6./(3*8)),0); AmpR1(1,1)=d1;AmpR1(2,2)=d3; AmpR2(1,3)=d3;AmpR2(2,4)=d1; AmpR3(1,2)=d2;AmpR3(2,3)=d2; AmpL1=Transpon(AmpR1);AmpL2=Transpon(AmpR2);AmpL3=Transpon(AmpR3); };
my_comp URCinnerpod(int l,int s,int u,my_comp c,const CVecCl &a,const CVecCl &b) { long double re=my_real(c),im=my_imag(c); my_comp tmp; for (int k=l;k<=u;k+=s) { tmp=a[k]*b[k];re+=my_real(tmp);im+=my_imag(tmp);} return my_comp(re,im); };
CVecCl operator/(const CVecCl &vec,const my_comp coef) { CVecCl ret=vec; if (fabs(coef)>MathZer) {for (int k=1;k<=my_real(ret.Ptr[0]);k++) ret.Ptr[k]/=coef;} else { for (int k=1;k<=my_real(ret.Ptr[0]);k++) ret.Ptr[k]=my_comp(MathInf,MathInf); cout<<"Error......... Zero Division in CVecCl/n";} return ret; };
void FormIntArr(MessRelaxClcPar *RelaxClc,MessRelaxInpPar &RelaxPar, double H,double Qs,double Eta,double Is) { int N=8;//Mat.Dim(); CMatrCl Mat(N),TimeShiftLeft,TimeShiftRight; CMatrCl Mat3,Mat3Eig,Mat3L,Mat3R, Mat1,Mat1Eig,Mat1L,Mat1R; CMatrCl Uni3(4),Uni1(2);Uni3=Uni3*0+1;Uni1=Uni1*0+1; TimeShiftLeft=Uni3;TimeShiftRight=Uni1; CVecCl Int(N),Pos(N); RelaxPar.Times[0]=0; RelaxClc[0].EndTime=0; for (int k=1;k<=RelaxPar.NumHam;k++) { QsHMat(Mat,RelaxPar.Teta[k],RelaxPar.Phi[k],H, -Qs, Eta, -Is,&Mat3,&Mat1); RelaxClc[k].EndTime=RelaxPar.Times[k]; // CMatrCl AmpL,AmpR; // AmpL=R0HQsAmpVec_(); // AmpR=TimeShiftRight*AmpL;AmpL=Conj(Transpon(Conj(Transpon(AmpL))*TimeShiftLeft)); CMatrCl Eig,Lft,Rgt; Mat1=Transpon(Mat1); GetVecIntTurn_(Int,Pos,Mat3,Mat1,TimeShiftLeft,TimeShiftRight, &Mat3Eig,&Mat3L,&Mat3R,&Mat1Eig,&Mat1L,&Mat1R); RelaxClc[k].RelInt=Int; RelaxClc[k].Freq=Pos; Eig=Mat3Eig; for (int i=1;i<=Mat3.Dim();i++) Eig(i,i)=exp(my_comp(0,-my_real(Mat3Eig(i,i))* (RelaxPar.Times[k]-RelaxPar.Times[k-1]))); Mat3=Mat3L*Eig*Mat3R; TimeShiftLeft= Mat3*TimeShiftLeft; Eig=Mat1Eig; for ( i=1;i<=Mat1.Dim();i++) Eig(i,i)=exp(my_comp(0,my_real(Mat1Eig(i,i))* (RelaxPar.Times[k]-RelaxPar.Times[k-1]))); Mat1=Mat1L*Eig*Mat1R; TimeShiftRight=TimeShiftRight*Mat1; } };
/// // ======================= Mul Var ============================ // //int MaxNit; void GenerateIntVar(CMatrCl &Ham3,CMatrCl &Rot3Rgt, CMatrCl &Ham1,CMatrCl &Rot1Lft, double t0,double t1,double MaxNorm,my_comp *&res,double &Tstp,int &Nit) { double M=max<double>(MatrNorm(Ham3),MatrNorm(Ham1)); CMatrCl Uni3(4),Uni1(2);Uni3=Uni3*0+1;Uni1=Uni1*0+1; Nit=int((t1-t0)*M/MaxNorm)+1; //Nit=1; Tstp=(t1-t0)/Nit; //if (Nit>MaxNit) MaxNit=Nit; // CMatrCl AmpR,AmpL; // AmpR=R0HQsAmpVec_();AmpL=Conj(Transpon(AmpR)); CMatrCl AmpR1,AmpL1,AmpR2,AmpL2,AmpR3,AmpL3; FormAmp(AmpR1,AmpL1,AmpR2,AmpL2,AmpR3,AmpL3); CMatrCl H3=Uni3+Ham3*my_comp(0,Tstp), H1=Uni1-Transpon(Ham1)*my_comp(0,Tstp); // H3=Uni3+Transpon(Ham3*my_comp(0,Tstp)), // H1=Uni1-Ham1*my_comp(0,Tstp); delete []res;res=new my_comp[Nit+1];res[0]=Nit; for (int k=1;k<=Nit;k++) { Rot3Rgt=H3*Rot3Rgt; Rot1Lft=Rot1Lft*H1; // Rot3Rgt=Rot3Rgt*H3; // Rot1Lft=H1*Rot1Lft; res[k]=Trace(AmpR1*Rot3Rgt*AmpL1*Rot1Lft)/M_PI+ Trace(AmpR2*Rot3Rgt*AmpL2*Rot1Lft)/M_PI+ Trace(AmpR3*Rot3Rgt*AmpL3*Rot1Lft)/M_PI; // Rot1Lft=H1*Rot1Lft; // res[k]=Trace(AmpL*DirectMultiplyOfMat(Rot3Rgt,Rot1Lft)*AmpR)/M_PI; // The same as trace, but we have not to transpon(Ham1) // and multiply Rot3,Rot1 from the same side //cout<<t0<<" "<<my_real(res[k])<<" "<<my_imag(res[k])<<"\n";t0+=Tstp; } };
main() { unsigned char ret; unsigned char buf[8]; unsigned char i=0; unsigned char l1=strlen(pass); unsigned char l2; lcd_init(); lcd_cmd(0x80); lcd_string("password:"******"Invalid"); delay_ms(5000); } else { //ret=strcmp(pass,buf); ret=my_comp(pass,buf,l2); if(ret==0) { lcd_cmd(0x01); lcd_string("Valid"); delay_ms(5000); } else { lcd_cmd(0x01); lcd_string("Invalid"); delay_ms(5000); } } }
int URCunsymdet(CMatrCl &a,double eps,my_comp &d1,int &d2,int *rear) { int i,j,k,l,N=a.Dim(); my_comp x,y; double *tmp=new double[N+1];tmp[0]=N; double xd,yd; for (i=1;i<=N;i++) tmp[i]=1/sqrt(fabs(URCinnerpod(1,1,N,0,CMatrCl::GetRow(a,i),CMatrCl::GetRow(a,i)))); d1=my_comp(1,0);d2=0; // d1=0;d2=1; for (k=1;k<=N;k++) { //cout<<" k= "<<k<<"\n"; l=k;xd=0; for (i=k;i<=N;i++) { y=URCinnerpod(1,1,k-1,-a(i,k),CMatrCl::GetRow(a,i),CMatrCl::GetCol(a,k)); //cout<<" i= "<<i<<"\n"; a(i,k)=-y;yd=fabs(y*tmp[i]); if (yd>xd) {xd=yd;l=i;} } if (l!=k) { d1=-d1; for (j=1;j<=N;j++) { y=a(k,j); a(k,j)=a(l,j); a(l,j)=y; } tmp[l]=tmp[k]; } rear[k]=l; d1*=a(k,k); if (xd<8*eps) {delete []tmp;cout<<"Det=0. Cannot complete LU decomposion\n";return 0;} l1: //cout<<" d1= "<<d1<<"\n"; if (fabs(d1)>=1) { d1*=0.0625;d2+=4;goto l1; } l2: //cout<<"d1= "<<d1<<"\n"; if (fabs(d1)<0.0625) { d1*=16;d2-=4;goto l2; } x=-1/a(k,k); for (j=k+1;j<=N;j++) a(k,j)=x*URCinnerpod(1,1,k-1,-a(k,j),CMatrCl::GetRow(a,k),CMatrCl::GetCol(a,j)); } delete []tmp; return 1; };
void RelaxOneHamIntMul(MessRelaxInpPar &RelaxPar, double H,double Qs,double Eta,double Is,double Wid, double *x,double *y) { CMatrCl Rot3Rgt(4),Rot1Lft(2),Ham(8),Ham3(4),Ham1(2),tmp3(4),tmp1(2); Rot1Lft=Rot1Lft*0+1;Rot3Rgt=Rot3Rgt*0+1; my_comp *res=NULL; double Tstp; Wid=Wid/2; int Nit; //MaxNit=0; double CurT,CurItT,t0,t1; for (int xi=1;xi<=x[0];xi++) y[xi]=0; for (int t=1;t<=RelaxPar.NumHam;t++) { t1=RelaxPar.Times[t];t0=RelaxPar.Times[t-1]; QsHMat(Ham,RelaxPar.Teta[t],RelaxPar.Phi[t],H, -Qs, Eta, -Is,&Ham3,&Ham1); // GenerateIntVar(Ham3,Rot3Rgt,Ham1,Rot1Lft,t0,t1,0.01,res,Tstp,Nit); GenerateInt(Ham3,Rot3Rgt,Ham1,Rot1Lft,t0,t1,0.01,res,Tstp,Nit); CurT=t0; for (xi=1;xi<=x[0];xi++) { my_comp freq=my_comp(-Wid,x[xi]); CurItT=CurT; for (int ti=1;ti<=Nit;ti++) { y[xi]+=my_real(res[ti]*exp(freq*CurItT))*Tstp; CurItT+=Tstp; } } } delete []res; //cout<<MaxNit<<"\n"; //cout<<Ham3<<Ham1<<"\n"; };
my_comp operator*(const CVecCl &vec,const CVecCl &vec1) { my_comp s=my_comp(0,0); for (int k=1;k<=my_real(vec.Ptr[0]);k++) s+=vec.Ptr[k]*vec1.Ptr[k]; return s; };
CVecCl operator*(const CVecCl &vec,const my_comp coef) { CVecCl ret=vec; if (fabs(coef)>MathZer) {for (int k=1;k<=my_real(ret.Ptr[0]);k++) ret.Ptr[k]*=coef;} else { for (int k=1;k<=my_real(ret.Ptr[0]);k++) ret.Ptr[k]=my_comp(0,0);} return ret; };
CVecCl operator*(const CVecCl &vec, double coef) {return vec*my_comp(coef);}
int URComeig(CMatrCl &a,CMatrCl &Lft,CMatrCl &Rgt) { my_comp ctmp,c1,c2,s1,s2,ch,cg,ce,cb,cd,cki,cmi; double tem,tau,g,hj,te,tee,max,s,c,isw,de,d,root1,root2,sa,ca,cotx,cot2x; double sig,sx,cx,e,b,nd,eta,tse,cos2a,sin2a,tep,root,sh,cb1;//chsb,hr,hi, double sb,nc,tanh,ch1; int i,j,k,m,it,mark=0,N=a.Dim(); double *en=new double[N+1]; double eps=1e-14; Lft=a*0;Lft=Lft+1;Rgt=Lft; //CMatrCl Contr=a; // проверка числа выполненных операций for (it=1;it<=35;it++) { if (mark) goto done; // критерий сходимости tau=0; for (k=1;k<=N;k++) { tem=0; for (i=1;i<=N;i++) if (i!=k) tem+=fabs(my_real(a(i,k)))+fabs(my_imag(a(i,k))); tau+=tem; en[k]=tem+fabs(my_real(a(k,k)))+fabs(my_imag(a(k,k))); } // перестановка строк и столбцов for (k=1;k<N;k++) { max=en[k];i=k; for (j=k+1;j<=N;j++) if (en[j]>max) {max=en[j];i=j;} if (i!=k) { en[i]=en[k]; for (j=1;j<=N;j++) { ctmp=a(k,j);a(k,j)=a(i,j);a(i,j)=ctmp; ctmp=Rgt(k,j);Rgt(k,j)=Rgt(i,j);Rgt(i,j)=ctmp; } for (j=1;j<=N;j++) { ctmp=a(j,k);a(j,k)=a(j,i);a(j,i)=ctmp; ctmp=Lft(j,k);Lft(j,k)=Lft(j,i);Lft(j,i)=ctmp; } } } if (tau<100*eps) goto done; // перебор элементов матрицы mark=1; for (k=1;k<N;k++) { for (m=k+1;m<=N;m++) { ch=my_comp(0);g=0;hj=0; for (i=1;i<=N;i++) if ((i!=k) && (i!=m)) { ch+=a(k,i)*conj(a(m,i))-a(i,k)*conj(a(i,m)); te=norm(a(i,k))+norm(a(m,i)); tee=norm(a(k,i))+norm(a(i,m)); g+=te+tee;hj+=tee-te; } cb=a(k,m)+a(m,k); ce=a(k,m)-a(m,k); cd=a(k,k)-a(m,m); te= sqr(my_real(cb))+sqr(my_imag(ce))+sqr(my_real(cd)); tee=sqr(my_imag(cb))+sqr(my_real(ce))+sqr(my_imag(cd)); if (te>=tee) { isw=1;c=my_real(cb);s=my_imag(ce);d=my_real(cd);de=my_imag(cd); root2=sqrt(te); } else { isw=-1;c=my_imag(cb);s=-my_real(ce);d=my_imag(cd);de=my_real(cd); root2=sqrt(tee); } root1=sqrt(s*s+c*c); sig=-1;if (d>=0) sig=1; sa=0;ca=-1;if (c>=0) ca=1; if (root1<eps) { sx=0;sa=0;cx=1;ca=1; if (isw>0) e=my_real(ce);else e=my_imag(ce); if (isw>0) b=my_imag(cb);else b=-my_real(cb); nd=sqr(d)+sqr(de); goto enter1; } if (fabs(s)>eps) {ca=c/root1;sa=s/root1;} cot2x=d/root1; cotx=cot2x+(sig*sqrt(1+sqr(cot2x))); sx=sig/sqrt(1+sqr(cotx));cx=sx*cotx; // определение параметров вращения eta=(my_real(ce)*my_real(cb)+my_imag(ce)*my_imag(cb))/root1; tse=(my_real(cb)*my_imag(cb)-my_real(ce)*my_imag(ce))/root1; te =sig*(-root1*de+tse*d)/root2; tee=(d*de+root1*tse)/root2; nd =sqr(root2)+sqr(tee); tee=hj*cx*sx;cos2a=sqr(ca)-sqr(sa); sin2a=2*ca*sa;tem=my_real(ch)*cos2a+my_imag(ch)*sin2a; tep=my_imag(ch)*cos2a-my_real(ch)*sin2a; ch =sqr(cx)*ch+my_comp(-sqr(sx)*tem-ca*tee,sqr(sx)*tep-sa*tee); b=isw*te*ca+eta*sa; e=ca*eta-isw*te*sa; enter1: s=my_real(ch)-sig*root2*e; c=my_imag(ch)-sig*root2*b; root=sqrt(sqr(c)+sqr(s)); if (root<eps) {cb1=1;ch1=1;sb=0;sh=0;goto trans;} cb1=-c/root;sb=s/root; tee=cb1*b-e*sb;nc=sqr(tee); tanh=root/(g+2*(nc+nd)); ch1=1/sqrt(1-sqr(tanh)); sh=ch1*tanh; // подготовка к преобразованию trans: tem=sx*sh*(sa*cb1-sb*ca); c1=my_comp(cx*ch1-tem,-sx*sh*(ca*cb1+sa*sb)); c2=my_comp(cx*ch1+tem,my_imag(c1)); tep=sx*ch1*ca;tem=cx*sh*sb; s1=my_comp(tep-tem,0);s2=my_comp(-tep-tem,0); tep=sx*ch1*sa;tem=cx*sh*cb1; s1=my_comp(my_real(s1),tep+tem);s2=my_comp(my_real(s2),tep-tem); // проверка выполнять преобразование или нет tem=fabs(s1);tep=fabs(s2); if ( (tem>eps) || (tep>eps) ) { mark=0; // левое преобразование for (i=1;i<=N;i++) { cki=a(k,i);cmi=a(m,i); a(k,i)=c1*cki+s1*cmi; a(m,i)=s2*cki+c2*cmi; cki=Rgt(k,i);cmi=Rgt(m,i); Rgt(k,i)=c1*cki+s1*cmi; Rgt(m,i)=s2*cki+c2*cmi; } // правое преобразование for (i=1;i<=N;i++) { cki=a(i,k);cmi=a(i,m); a(i,k)=c2*cki-s2*cmi; a(i,m)=-s1*cki+c1*cmi; cki=Lft(i,k);cmi=Lft(i,m); Lft(i,k)=c2*cki-s2*cmi; Lft(i,m)=-s1*cki+c1*cmi; } } } } } done: //cout<<Contr-Lft*a*Rgt; delete []en; return 1; }