anderkve / FYS3150

https://anderkve.github.io/FYS3150
26 stars 14 forks source link

Project 1: Problem 7 vs. 9 #38

Closed sunnikbe closed 1 year ago

sunnikbe commented 2 years ago

In Problem 9 it says to solve the alg. from Prob. 6 using the special algorithm, i.e. with the g-vector having the solutions we found in Prob. 4 (g = h^2f_1 + v_0, h^2f_2, ... etc.), if I understand correctly.

My issue is that I did this in Problem 7, so now I'm wondering what I was supposed to do for Problem 7?

Thanks :)

anderkve commented 2 years ago

Hi @sunnikbe!

The term "special algorithm" is not referring to anything related to the g vector. We solve exactly the same matrix equation in problem 7 and problem 9. But in Problem 6 you wrote down an algorithm that works for the case where:

That is, you wrote down an algorithm that is actually more general than what is strictly needed for our particular differential equation problem. (Hence the comment at the beginning of Problem 6, about leaving aside the Poisson equation for a moment.)

In Problem 7 you used this general algorithm to solve our particular case, in which the A matrix consists of the specific vectors a = [-1, -1, ..., -1], b = [2, 2, ..., 2] and c = [-1, -1, ..., -1]

The point in Problem 9 is this: what if we write down an algorithm that already assumes the specific case a = [-1, -1, ..., -1], b = [2, 2, ..., 2] and c = [-1, -1, ..., -1], i.e. an algorithm where we don't have to treat all the a_i, b_i and c_i as potentially different values. This means that we can simply insert values -1 for a and c vector elements in our original algorithm, and similarly insert 2 for b vector elements. The challenge for you in Problem 9 is to write down this simpler algorithm (the "special algorithm"), and investigate if this simplification reduces the number of FLOPs, and if you can observe any speedup with this algorithm compared to the general algorithm from Problem 6 and 7.

(A useful consistency check is of course that the solution v you get from running the codes in Problem 7 and Problem 9 should be identical, since the two versions of the algorithm are used to solve exactly the same equation A v = g.)

Hope that helps! Just ask if things are still unclear. :)