Apologies in advance to those who has to read through my poor coding skill
The objective of this coding is to first develop a 17x17 matrix and solve for the 17 unknowns using methods presented in linear algebra.
The part I am having the most difficulty is:
x11 x12 x13....x1j
x21 .......... x2j
import numpy as np
import math as mt
while i <=18:
for j in range(17):
So your code suffers from two mistakes. The first that in python, you start counting from zero; you may think of your matrix as having 17 rows, 1 to 17, but python sees it as going from 0 to 16. The second is that when working with numpy, you should build your array first, and then insert your calculated values. There's a good explanation of why here:(How do I create an empty array/matrix in NumPy?).
I made r an array for consistency's sake, and I inserted the calculated values into k2. I'm not sure k was for.
import numpy as np import math as mt r=np.array([2,2.8,3.2,3.5,3.7,3.8,3.8,3.8,3.8,3.8,3.8,3.8,3.7,3.5,3.2,2.8,2]) n=np.linspace(1,17,17) m=np.linspace(1,17,17) l=1 k2 = np.empty(shape=(17,17)) i=0 j=0 while i <=16: while j<=16: h1=mt.sqrt(r[i]**2+(l*(n[i]-m[j])+l/2)**2) h2=mt.sqrt(r[i]**2+(l*(n[i]-m[j])-l/2)**2) h=np.array(h1-h2) k2[i,j]= h j+=1 j=0 i+=1
I hope this was helpful to you, and good luck with your python practicing. Please up vote if this was of help to you.