2021-04-20 14:41:15 +0200 received badge ● Notable Question (source) 2020-05-01 21:34:23 +0200 received badge ● Popular Question (source) 2019-01-10 10:03:49 +0200 asked a question Number of elements in vector I want to implement the Gauss-Seidel method for solving linear systems for a university project, and I'm stuck on how to get the number of elements in the product vectorb = A * x. Here's my code: def Gauss_Seidel(m, v, initial): n = v.size() <--------- prev = vector(RR, n) nex = vector(RR, n) prev = initial while abs(inf_vector_norm(nex) - inf_vector_norm(nex)) > 0.1: for i in xrange(n): s1 = sum(m[i,j] * nex[j] for j in xrange(i)) s2 = sum(m[i,j] * prev[j] for j in xrange(j+1, n+1)) nex[i] = (v[i] - s1 - s2) / m[i,i] return nex  In the code, 'm' is the input matrix, 'v' is the product of the matrix and our variable vector, and 'initial' is the starting guess for Gauss-Seidel's Method. The line pointed by that arrow is the one I'm interested in, and it's showing what I want to accomplish. I searched for it on Sage textbooks, but they are oddly silent on the matter of vectors. Any ideas? Also any other recommendations and advice on my code is more than welcome. 2019-01-08 11:42:16 +0200 commented answer Generic Symbolic function as input in actual funciton Ok got it. Again many thanks! 2019-01-08 11:06:01 +0200 commented answer Generic Symbolic function as input in actual funciton Thanks a lot! I have the exact same results. After I fixed the error thing I also get a logical result on this scope too: 0 (0.8571428346650166, 7, 9.64919707358014e-05)  Just to clarify, because I can't get the "%time" function you mentioned, what is the syntax of it? I tried to even copy an example from Sage's documentation, however I can't seem to get it to work. I have the "time" library imported. Meaning what I type exactly to get it to work? This is what I get for typing this: %time Newton_Raphson(f, 0) Error in lines 48-48 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute flags=compile_flags) in namespace, locals File "", line 1, in 10^-6: NR = start - foo(start)/dfoo(start) start = NR error = (NR - start) noNR += 1 t1 = time.time() tNR = t1 - t0 return NR, noNR, error, tNR  Any ideas on this? Also do you have any other suggestions on this code?