"""Independent SciPy sparse direct/Newton solution of the specified fixed-boundary problem. No JavaScript results are inputs. Generated values are checked by the Node test suite. """ import json, pathlib import numpy as np import scipy from scipy.sparse import lil_matrix, diags from scipy.sparse.linalg import spsolve MU0=1.25663706127e-6 def solve(n,mode): R=np.linspace(1.5,2.5,n); Z=np.linspace(-.5,.5,n); h=1/(n-1) m=(n-2)**2; A=lil_matrix((m,m)); rr=np.zeros(m); zz=np.zeros(m) for j in range(1,n-1): for i in range(1,n-1): k=(i-1)+(n-2)*(j-1); r=R[i]; z=Z[j]; rr[k]=r; zz[k]=z A[k,k]=-4/h**2 for ii,jj,c in [(i+1,j,1/h**2-1/(2*r*h)),(i-1,j,1/h**2+1/(2*r*h)),(i,j+1,1/h**2),(i,j-1,1/h**2)]: if 0