В Matlab x=A\b
;решает линейную систему Ax = b. Можно ли имитировать то же самое в C ++? Возможно с перегрузкой оператора, но как использовать \ вместо / в следующей программе?
friend Vector operator/(const Vector &b, const Matrix &A)
{ //BiCG Algorithm is used here.
int row=A.getrowdim();
int col=A.getcoldim();
Vector x(row,0.0);
Vector r(row,0.0);
Vector s(row,0.0);
Vector u(row,0.0);
Vector v(row,0.0);
Vector w(row,0.0);
Vector p(row,0.0);
double rho0,beta,alpha,rho;
Vector t(row,0.0);
double norm;
r=b-A*x;
s=r;
rho0=1;
for(int k=1;k<M;k++)
{
rho=s*r;
beta=rho/rho0;
u=r+beta*u;
w=s+beta*w;
v=A*u;
alpha=rho/(w*v);
x=x+alpha*u;
r=r-alpha*v;
s=s-alpha*(Transpose(A)*w);
norm=r.norm(2);
cout<<"Step Number "<<k<<" xnorm "<<norm<<endl;
if(norm<eps)
break;
rho0=rho;
}
return x;
}