Question: C + + Code Diagonal dominance: i : aii > j = i | aij | Solve the linear system by both methods above. How
C Code
Diagonal dominance:
i : aii
ji
aij
Solve the linear system by both methods above. How accurate
is the solution?
Experimment with different matrix sizes and amounts of
#include
using std::cout,std::cin;
#include
#include
using std::string;
#include
using std::ranges::views::iota,
std::ranges::views::filter,
std::ranges::views::transform;
#include
using std::accumulate;
#include
using namespace Eigen;
::Matrix, Eigen::Vector;
Jacobi Iterative method with seq
template typename MatrixType,typename VectorType
void JacobiSolve MatrixType AVectorType sol,VectorType rhs
auto tmpsol;
set initial guess to identically one
int siz Arows;
for auto& v : sol
v ;
for a number of iteration
for auto it : iota
one step of Jacobi
cout it: it
sol
;
Jacobi Iterative method with ranges
template typename MatrixType,typename VectorType
void JacobiSolve MatrixType AVectorType sol,VectorType rhs
auto tmpsol;
set initial guess to identically one
int siz Arows;
for auto& v : sol
v ;
for a number of iteration
for auto it : iota
one step of Jacobi
cout it: it
sol
;
int main
const int siz;
Matrix A;
Vector sol,rhstmp;
cout "Matrix size: Arows Acols Asize
;
for auto& v : rhs
v ;
cout rhs
;
for auto row : iotasiz
solrow staticcast row ;
Arowrow siz;
for auto col : iotasiz
if rowcol continue;
Arowcol;
cout "sol:
sol
;
rhs Asol;
cout rhs:
rhs
;
cout Solve
;
JacobiSolve Asol,rhs ;
cout Solve
;
JacobiSolve Asol,rhs ;
Matrix Af;
or: MatrixXf Af;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
