xxxxxxxxxxbegin using Pkg Pkg.activate(mktempdir()) Pkg.add("PyPlot") Pkg.add("PlutoUI") Pkg.add("DataFrames") using PlutoUI using PyPlot using DataFramesendMatrices from partial differential equations
As we focus in this course on partial differential equations, we need discuss matrices which evolve from the discretization of PDEs.
Are there any structural or numerical patterns in these matrices we can take advantage of with regard to memory and time complexity when solving linear systems ?
In this lecture we introduce a relatively simple "drosophila" problem which we will use do discuss these issues.
For the start we use simple structured disceretization grids and a finite difference approach to the discretization. Later, this will be generalized to more general grids and to finite element and finite volume discretization methods.
Heat conduction in a one-dimensional rod
Heat source
: ambient temperatures : boundary heat transfer coefficientSecond order boundary value problem in
:
The solution
describes the equilibrium temperature distribution. Behind the second derivative is Fouriers law and the continuity equationIn math, the boundary conditions are called "Robin" or "third kind". They describe a heat in/outflux proportional to the difference between rod end temperature and ambient temperature
Fix a number of discretization points N
Let
Let
be discretization points
11xxxxxxxxxxN=11plotgrid (generic function with 1 method)xxxxxxxxxxplotgrid(N)Finite difference approximation
We can approximate continuous functions
xxxxxxxxxxplotgrid(N,func=x->0.5*sin(8*x)^2)Let
approximations for andWe can use a finite difference approximation to approximate
Same approach for second derivative:
Finite difference approximation of the PDE:
xxxxxxxxxxplotgrid(N,mirror=true)Here, we introduced "mirror values"
and in order to approximate the boundary conditions accurately, such that the finite difference formulas used to approximate or are centered around these values.After rearranging, these values can be expressed via the boundary conditions:
Finally, they can be replaced in
Then, the system after multiplying by
The resulting discretization matrix is
Outside of the three diagonals, the entries are zero.
The right hand side is:
Let us define functions assembling these:
heatmatrix1d (generic function with 1 method)xxxxxxxxxxfunction heatmatrix1d(N;α=1) A=zeros(N,N) h=1/(N-1) A[1,1]=1/h+α for i=2:N-1 A[i,i]=2/h end for i=1:N-1 A[i,i+1]=-1/h end for i=2:N A[i,i-1]=-1/h end A[N,N]=1/h+α Aendheatrhs1d (generic function with 1 method)xxxxxxxxxxfunction heatrhs1d(N;vl=0,vr=0,func=x->0,α=1) h=1/(N-1) F=zeros(N) F[1]=h/2*func(0)+α*vl for i=2:N-1 F[i]=h*func((i-1)*h) end F[N]=h/2*func(1)+α*vr Fend100xxxxxxxxxxα=10010000xxxxxxxxxxN1=1000010000×10000 Array{Float64,2}:
10099.0 -9999.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0
-9999.0 19998.0 -9999.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 -9999.0 19998.0 -9999.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 -9999.0 19998.0 -9999.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 -9999.0 19998.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 -9999.0 … 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
⋮ ⋱
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 … -9999.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 19998.0 -9999.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 -9999.0 19998.0 -9999.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 -9999.0 19998.0 -9999.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 -9999.0 10099.0xxxxxxxxxxA=heatmatrix1d(N1,α=α)5.0005e-5
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
0.00010001
5.0005e-5
xxxxxxxxxxb=heatrhs1d(N1,func=x->1,α=α)0.005
0.00505
0.00509999
0.00514997
0.00519994
0.0052499
0.00529985
0.00534979
0.00539972
0.00544964
0.00549955
0.00554945
0.00559934
0.00564922
0.00569909
0.00574895
0.0057988
0.00584864
0.00589847
0.00594829
0.00544964
0.00539972
0.00534979
0.00529985
0.0052499
0.00519994
0.00514997
0.00509999
0.00505
0.005
xxxxxxxxxxu=A\bxxxxxxxxxxbegin clf() plot(collect(0:1/(N1-1):1),u) grid() gcf()endFor this example, we created an
Fraction of nonzero entries: 0.00029998
Ratio of nonzero entries to number of unknowns: 2.9998
In fact, this matrix has
nonzero entries.
2D heat conduction
Just pose the heat problem in a 2D domain
We use 2D regular discretization
This just comes from summing up the 1D finite difference formula for the
We do not discuss the boundary conditions here.
The
plotgrid2d (generic function with 1 method)xxxxxxxxxxfunction plotgrid2d(N;text=true, func=nothing) clf() ax=PyPlot.axes(aspect=1) x=[(i-1)/(N-1) for i=1:N] y=[(i-1)/(N-1) for i=1:N] for i=1:N plot([x[i],x[i]],[0,1],linewidth=1,color="k") plot([0,1],[y[i],y[i]],linewidth=1,color="k") end if func!=nothing f=[func(x[i],y[j]) for i=1:N, j=1:N] contourf(x,y,f,cmap="hot") end if text ij=1 for j=1:N for i=1:N ax.text(x[i],y[j]-0.035,"\$x_{$(ij)}\$",fontsize=10,color=:blue) ij=ij+1 end end end fig=PyPlot.gcf() fig.set_size_inches(5,5) figendxxxxxxxxxxplotgrid2d(5)Matrix and right hand side assembly inspired by the finite volume method which will be covered later in the course. The result is the same as for the finite difference method with the mirror trick for the boundary condition.
heatmatrix2d (generic function with 1 method)xxxxxxxxxxfunction heatmatrix2d(n;α=1) function update_pair(A,v,i,j) A[i,j]+=-v A[j,i]+=-v A[i,i]+=v A[j,j]+=v end N=n^2 h=1.0/(n-1) A=zeros(N,N) l=1 for j=1:n for i=1:n if i<n update_pair(A,1.0,l,l+1) end if i==1|| i==n A[l,l]+=α end if j<n update_pair(A,1,l,l+n) end if j==1|| j==n A[l,l]+=α end l=l+1 end end Aendheatrhs2d (generic function with 1 method)xxxxxxxxxxfunction heatrhs2d(n; rhs=(x,y)->0,bc=(x,y)->0,α=1.0) h=1.0/(n-1) x=collect(0:h:1) y=collect(0:h:1) N=n^2 f=zeros(N) for i=1:n-1 for j=1:n-1 ij=(j-1)*n+i f[ij]+=h^2/4*rhs(x[i],y[j]) f[ij+1]+=h^2/4*rhs(x[i+1],y[j]) f[ij+n]+=h^2/4*rhs(x[i],y[j+1]) f[ij+n+1]+=h^2/4*rhs(x[i+1],y[j+1]) end end for i=1:n ij=i fac=h if i==1 || i==n fac=h/2 end f[ij]+=fac*α*bc(x[i],0) ij=i+(n-1)*n f[ij]+=fac*α*bc(x[i],1) end for j=1:n fac=h if j==1 || j==n fac=h/2 end ij=1+(j-1)*n f[ij]+=fac*α*bc(0,y[j]) ij=n+(j-1)*n f[ij]+=fac*α*bc(1,y[j]) end fend5xxxxxxxxxxn=50.0
0.0
0.0
0.0
0.0
0.0
0.03125
-0.0441942
0.03125
8.11834e-18
0.0
-0.0441942
0.0625
-0.0441942
-1.14811e-17
0.0
0.03125
-0.0441942
0.03125
8.11834e-18
0.0
8.11834e-18
-1.14811e-17
8.11834e-18
2.10904e-33
xxxxxxxxxxb2=heatrhs2d(n,rhs=(x,y)->sin(3*π*x)*sin(3*π*y),α=α)25×25 Array{Float64,2}:
202.0 -1.0 0.0 0.0 0.0 -1.0 0.0 … 0.0 0.0 0.0 0.0 0.0
-1.0 103.0 -1.0 0.0 0.0 0.0 -1.0 0.0 0.0 0.0 0.0 0.0
0.0 -1.0 103.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 -1.0 103.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 -1.0 202.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
-1.0 0.0 0.0 0.0 0.0 103.0 -1.0 … 0.0 0.0 0.0 0.0 0.0
0.0 -1.0 0.0 0.0 0.0 -1.0 4.0 0.0 0.0 0.0 0.0 0.0
⋮ ⋮ ⋱ ⋮
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 202.0 -1.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.0 103.0 -1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.0 103.0 -1.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.0 103.0 -1.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.0 202.0xxxxxxxxxxA2=heatmatrix2d(n,α=α)In order to inspect the matrix, we can turn it into a DataFrame, which can be browsed.
| x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1 | 202.0 | -1.0 | 0.0 | 0.0 | 0.0 | -1.0 | 0.0 | 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | -1.0 | 103.0 | -1.0 | 0.0 | 0.0 | 0.0 | -1.0 | 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 0.0 | -1.0 | 103.0 | -1.0 | 0.0 | 0.0 | 0.0 | -1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 0.0 | 0.0 | -1.0 | 103.0 | -1.0 | 0.0 | 0.0 | 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 0.0 | 0.0 | 0.0 | -1.0 | 202.0 | 0.0 | 0.0 | 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | -1.0 | 0.0 | 0.0 | 0.0 | 0.0 | 103.0 | -1.0 | 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 0.0 | -1.0 | 0.0 | 0.0 | 0.0 | -1.0 | 4.0 | -1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 0.0 | 0.0 | -1.0 | 0.0 | 0.0 | 0.0 | -1.0 | 4.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 0.0 | 0.0 | 0.0 | -1.0 | 0.0 | 0.0 | 0.0 | -1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 0.0 | 0.0 | 0.0 | 0.0 | -1.0 | 0.0 | 0.0 | 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
xxxxxxxxxxDataFrame(A2)4.35673e-7
4.4003e-5
-6.20691e-5
4.4003e-5
4.35673e-7
4.4003e-5
0.00459394
-0.00648112
0.00459394
4.4003e-5
-6.20691e-5
-0.00648112
0.00914388
-0.00648112
-6.20691e-5
4.4003e-5
0.00459394
-0.00648112
0.00459394
4.4003e-5
4.35673e-7
4.4003e-5
-6.20691e-5
4.4003e-5
4.35673e-7
xxxxxxxxxxu2=A2\b2xxxxxxxxxxbegin clf() h=1.0/(n-1) x=collect(0:h:1) y=collect(0:h:1) contourf(x,y,reshape(u2,n,n),cmap="hot") fig=gcf() fig.set_size_inches(5,5) figendIn order to achieve this, we stored a matrix which has only five nonzero diagonals as a full
Fraction of nonzero entries: 0.168
Ratio of nonzero entries to number of unknowns: 4.2
In fact, this matrix has
nonzero entries.
... there must be a better way!