Question: A = [ 1 ? ? ? ? 1 h 2 - 2 h 2 1 h 2 ? ? ? 1 h 2 -

A=[1????1h2-2h21h2???1h2-2h21h2??ddotsddotsddots??1h2-2h21h2??1???]
a) Code a function for A for a given number of steps N. The easiest way to do this is to define three
column vectors containing the entries of the main diagonal (N+1 entries), subdiagonal (N entries) and
superdiagonal (N entries). The np.ones command is useful here:
These vectors can be combined into a tridiagonal matrix using the np.diag command: ??# superdiagonal (N entries)
sup=...
These vectors can be combined into a tridiagonal matrix using the np. diag command:
??# create tridiagonal matrix
A=np.diag(main)+np.diag(sup,1)+np.diag(sub,-1)
Your function should take arguments N,L and h, and return the matrix A.In the steady-state situation the temperature T is a function of x, the distance along the rod, but not a
function of time. T(x) is determined by Laplace's equation in 1D:
d2Tdx2=0,T(0)=TH,T(L)=TC
As in the lectures, we divide the rod into N intervals. In lectures the grid used was separated by
x=LN; here we use x=h. We replace the derivative term by a central difference approximation,
and evaluate the resulting equation at each grid point. This gives a set of linear equations
Tk-1-2Tk+Tk+1h2=0,k=1,dotsN-1
From the boundary conditions, we also have
T0=TH, and ,TN=TC
Taking the above two equations gives a total of N+1 equations in the unknowns T0,dots,TN.
In [1]: import numpy as np
import matplotlib.pyplot as plt
%config InlineBackend.figure_format='retina'
Task 1: Tridiagonal matrix (A) and vector (b) for a boundary
value problem
Steady-state problems often result in a system of linear equations of the form Af=b where A is a
tridiagonal (N+1)(N+1) matrix. Suppose h=LN and
 A=[1????1h2-2h21h2???1h2-2h21h2??ddotsddotsddots??1h2-2h21h2??1???] a) Code a function for A for a given number

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!