Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions