I have a numerical analysis assignment and I need to find some coefficients by multiplying matrices. We were given an example in Mathcad, but now we have to do it in another programming language so I chose Python.
The problem is, that I get different results by multiplying matrices in respective environments. Here's the function in Python:
from numpy import * def matrica(C, n): N = len(C) - 1 m = N - n A = [[0] * (N + 1) for i in range(N+1)] A[0][0] = 1 for i in range(0, n + 1): A[i][i] = 1 for j in range(1, m + 1): for i in range(0, N + 1): if i + j <= N: A[i+j][n+j] = A[i+j][n+j] - C[i]/2 A[int(abs(i - j))][n+j] = A[int(abs(i - j))][n+j] - C[i]/2 M = matrix(A) x = matrix([[x] for x in C]) return [float(y) for y in M.I * x] As you can see I am using numpy library. This function is consistent with its analog in Mathcad until return statement, the part where matrices are multiplied, to be more specific. One more observation: this function returns correct matrix if N = 1.
import numpy as np. Show what you get and what you expect.