uwhpsc-2016 / homework1

Homework #1
1 stars 1 forks source link

Homework #1, Exercise 3.7: Can't adjust epsilon in jacobi_step & gauss_seidel_step #55

Open hughkf opened 8 years ago

hughkf commented 8 years ago

In exercise 3.7, we are supposed to first plot the difference r(k) = b − A*x(k) after k iterations of jacobi_step (this question applies to Gauss-Seidel as well), for k between 1 and some large number, call it N. First, what number N should we use?

I wrote a loop that does the equivalent of jacobi_iteration, but stops after k iterations. Then the question asks "What happens to these plots when you decrease epsilon to 1e−20?" Since we are using k as an exit condition, how can we also use epsilon as an exit condition? In other words, we didn't use epsilon at all in our code to make our plots, so how would we adjust epsilon in that code?

mvelegar commented 8 years ago

@hughkf The simplest way to do this is to have a logical OR in your exit condition, your algorithm should exit if the two norm of the difference xkp1-xk < epsilon, OR k > N (maximum number of iterations allowed)

hughkf commented 8 years ago

Thanks, @mvelegar !

cswiercz commented 8 years ago

Reopening since this may be useful to other students.