// File: /workspace/github_cpp_makefile_star2_O2/IlanPrice[P]Linear-Algebra-Library-in-Cplusplus/Matrix.cpp
// Function: jacobi(Matrix const&, Vector const&)
Vector jacobi(const Matrix& A, const Vector& b)
{
	std::ofstream JacobiIterates;
	JacobiIterates.open("JacobiIterates.txt");
	int n = length(b);
	Vector x(n);
	Vector xnext(n);
	Vector r = b - A*x;
	double Tol = 1e-14;
	int iter = 0;
	while (norm(r) > Tol & iter < 10000)
	{
		for (int i = 1; i<=n; i++)
		{
			double sum = 0;
			for (int j=1; j<=n; j++)
			{
				if (i != j) { sum = sum + A(i,j)*x(j);}
				else if (i==j) {}
			}
			xnext(i) = (b(i) - sum)/A(i,i);
			JacobiIterates << std::setprecision(15) << xnext(i)<< ",";
		}
		r = b - A*xnext;
		x = xnext;
		JacobiIterates << "\n";
		iter++;
	}

	JacobiIterates.close();
	return xnext;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x1140
leaq 0x2921(%rip), %rsi      # 0x95d3
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x2141
movl %eax, %r12d
movq %rbx, %r14
leaq 0x48(%rsp), %rdi
movl %eax, %esi
callq 0x186c
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x186c
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %r15, %rsi
callq 0x38bd
leaq 0x38(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %r14, %rsi
callq 0x1a3c
leaq 0x28(%rsp), %rdi
callq 0x1908
xorl %ebx, %ebx
testl %r12d, %r12d
movl $0x0, %eax
cmovgl %r12d, %eax
incl %eax
movl %eax, 0x24(%rsp)
negl %r12d
leaq 0x38(%rsp), %rbp
leaq 0x48(%rsp), %r13
movq %r14, 0x58(%rsp)
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0x20c8
cmpl $0x270f, %ebx           # imm = 0x270F
ja 0x6ede
ucomisd 0x2589(%rip), %xmm0     # 0x92e0
jbe 0x6ede
movl %ebx, 0x20(%rsp)
xorl %ebx, %ebx
pushq $0x1
popq %rbp
cmpl 0x24(%rsp), %ebp
je 0x6e6b
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
pushq $0x1
popq %rax
movl %eax, %r14d
leal (%r12,%r14), %eax
cmpl $0x1, %eax
je 0x6dd3
leal (%rbx,%r14), %eax
cmpl $0x1, %eax
je 0x6dce
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x2030
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
incl %r14d
jmp 0x6d80
movq 0x58(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
callq 0x1ee2
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
movl %ebp, %esi
movl %ebp, %edx
callq 0x3a1a
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x8(%rsp), %rdi
movl %ebp, %esi
callq 0x2030
movsd 0x10(%rsp), %xmm0
subsd 0x18(%rsp), %xmm0
divsd 0x60(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x80(%rsp,%rax)
movq 0x8(%rsp), %rdi
movl %ebp, %esi
callq 0x2030
movsd (%rax), %xmm0
leaq 0x78(%rsp), %rdi
callq 0x1130
movq %rax, %rdi
leaq 0x2789(%rip), %rsi      # 0x95e6
callq 0x10e0
incl %ebp
decl %ebx
jmp 0x6d66
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x38bd
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1a3c
leaq 0x38(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1da0
movq %rbx, %rdi
callq 0x1908
leaq 0x68(%rsp), %rdi
callq 0x1908
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x1da0
movl 0x20(%rsp), %ebx
leaq 0x78(%rsp), %rdi
leaq 0x23f8(%rip), %rsi      # 0x92ca
callq 0x10e0
incl %ebx
jmp 0x6d38
leaq 0x78(%rsp), %rdi
callq 0x1100
leaq 0x38(%rsp), %rdi
callq 0x1908
leaq 0x48(%rsp), %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x1110
movq 0x8(%rsp), %rax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6f60
movq %rax, %r14
leaq 0x28(%rsp), %rdi
jmp 0x6f68
movq %rax, %r14
jmp 0x6f6d
movq %rax, %r14
jmp 0x6f77
jmp 0x6f37
jmp 0x6f37
movq %rax, %r14
jmp 0x6f81
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x1908
jmp 0x6f4e
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x1908
jmp 0x6f63
jmp 0x6f60
jmp 0x6f60
jmp 0x6f60
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x1908
movq 0x8(%rsp), %rdi
callq 0x1908
leaq 0x48(%rsp), %rdi
callq 0x1908
leaq 0x78(%rsp), %rdi
callq 0x1110
movq %r14, %rdi
callq 0x1180