// File: 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:
subq $0x348, %rsp            # imm = 0x348
movq %rdi, 0x90(%rsp)
movq %rdi, %rax
movq %rax, 0x98(%rsp)
movq %rdi, 0x340(%rsp)
movq %rsi, 0x338(%rsp)
movq %rdx, 0x330(%rsp)
leaq 0x130(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x2170
movq 0xa0(%rsp), %rdi
leaq 0x505d(%rip), %rsi      # 0x125c3
movl $0x10, %edx
callq 0x2050
jmp 0xd572
movq 0x330(%rsp), %rdi
callq 0x4090
movl %eax, 0x8c(%rsp)
jmp 0xd588
movl 0x8c(%rsp), %eax
movl %eax, 0x120(%rsp)
movl 0x120(%rsp), %esi
leaq 0x110(%rsp), %rdi
callq 0x2d70
jmp 0xd5ac
movq 0x90(%rsp), %rdi
movb $0x0, 0x10f(%rsp)
movl 0x120(%rsp), %esi
callq 0x2d70
jmp 0xd5ca
movq 0x330(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x338(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0x6f70
jmp 0xd5f9
movq 0x80(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
leaq 0xe8(%rsp), %rdx
callq 0x31a0
jmp 0xd618
leaq 0xe8(%rsp), %rdi
callq 0x2ea0
movsd 0x4c8b(%rip), %xmm0     # 0x122b8
movsd %xmm0, 0xe0(%rsp)
movl $0x0, 0xdc(%rsp)
leaq 0xf8(%rsp), %rdi
movl $0x2, %esi
callq 0x3fe0
movsd %xmm0, 0x78(%rsp)
jmp 0xd65b
movsd 0x78(%rsp), %xmm0
ucomisd 0xe0(%rsp), %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x2710, 0xdc(%rsp) # imm = 0x2710
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xda5a
movl $0x1, 0xd8(%rsp)
movl 0xd8(%rsp), %eax
cmpl 0x120(%rsp), %eax
jg 0xd958
xorps %xmm0, %xmm0
movsd %xmm0, 0xd0(%rsp)
movl $0x1, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
cmpl 0x120(%rsp), %eax
jg 0xd82b
movl 0xd8(%rsp), %eax
cmpl 0xcc(%rsp), %eax
je 0xd7ff
movsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0x338(%rsp), %rdi
movl 0xd8(%rsp), %esi
movl 0xcc(%rsp), %edx
callq 0x7250
movq %rax, 0x70(%rsp)
jmp 0xd720
movq 0x70(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movl 0xcc(%rsp), %esi
leaq 0x110(%rsp), %rdi
callq 0x3ee0
movq %rax, 0x60(%rsp)
jmp 0xd74a
movsd 0x68(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
movq 0x60(%rsp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xd0(%rsp)
jmp 0xd813
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0xdaea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0xdadd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0xdad0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x2ea0
jmp 0xdad0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0xda8a
movl 0xd8(%rsp), %eax
cmpl 0xcc(%rsp), %eax
jne 0xd811
jmp 0xd811
jmp 0xd813
jmp 0xd815
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0xd6c7
movq 0x330(%rsp), %rdi
movl 0xd8(%rsp), %esi
callq 0x3c10
movq %rax, 0x50(%rsp)
jmp 0xd846
movq 0x50(%rsp), %rax
movsd (%rax), %xmm0
movsd 0xd0(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x338(%rsp), %rdi
movl 0xd8(%rsp), %edx
movl %edx, %esi
callq 0x7250
movq %rax, 0x48(%rsp)
jmp 0xd87f
movq 0x90(%rsp), %rdi
movsd 0x40(%rsp), %xmm0
movq 0x48(%rsp), %rax
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0xd8(%rsp), %esi
callq 0x3ee0
movq %rax, 0x38(%rsp)
jmp 0xd8b3
movq 0x38(%rsp), %rax
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rax)
movl $0xf, %edi
callq 0x10e10
movl %eax, 0x2c(%rsp)
jmp 0xd8d2
movl 0x2c(%rsp), %eax
movl %eax, 0xc8(%rsp)
movl 0xc8(%rsp), %esi
leaq 0x130(%rsp), %rdi
callq 0x2160
movq %rax, 0x20(%rsp)
jmp 0xd8f8
movq 0x90(%rsp), %rdi
movl 0xd8(%rsp), %esi
callq 0x3ee0
movq %rax, 0x18(%rsp)
jmp 0xd913
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
callq 0x21d0
movq %rax, 0x10(%rsp)
jmp 0xd92d
movq 0x10(%rsp), %rdi
leaq 0x4c9d(%rip), %rsi      # 0x125d6
callq 0x20e0
jmp 0xd940
jmp 0xd942
movl 0xd8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd8(%rsp)
jmp 0xd69c
movq 0x90(%rsp), %rdx
movq 0x330(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x338(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x6f70
jmp 0xd984
movq 0x8(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x31a0
jmp 0xd9a0
leaq 0xf8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x39a0
jmp 0xd9b7
leaq 0xb8(%rsp), %rdi
callq 0x2ea0
leaq 0xa8(%rsp), %rdi
callq 0x2ea0
movq 0x90(%rsp), %rsi
leaq 0x110(%rsp), %rdi
callq 0x39a0
jmp 0xd9e8
leaq 0x48bb(%rip), %rsi      # 0x122aa
leaq 0x130(%rsp), %rdi
callq 0x20e0
jmp 0xd9fe
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0xd641
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
jmp 0xda4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x2ea0
leaq 0xa8(%rsp), %rdi
callq 0x2ea0
jmp 0xda8a
leaq 0x130(%rsp), %rdi
callq 0x2130
jmp 0xda69
movb $0x1, 0x10f(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x2ea0
testb $0x1, 0x10f(%rsp)
jne 0xdaa6
jmp 0xda99
leaq 0xf8(%rsp), %rdi
callq 0x2ea0
jmp 0xdad0
movq 0x90(%rsp), %rdi
callq 0x2ea0
leaq 0x110(%rsp), %rdi
callq 0x2ea0
leaq 0x130(%rsp), %rdi
callq 0x2140
movq 0x98(%rsp), %rax
addq $0x348, %rsp            # imm = 0x348
retq
movq 0x90(%rsp), %rdi
callq 0x2ea0
leaq 0x110(%rsp), %rdi
callq 0x2ea0
leaq 0x130(%rsp), %rdi
callq 0x2140
movq 0x128(%rsp), %rdi
callq 0x21b0
nopw %cs:(%rax,%rax)