Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function file, M = TriDiagonalMatrix ( n ) , that takes input arguments of an integer n and returns a square matrix of
Write a function file, M TriDiagonalMatrix n that takes input arguments of an integer n and
returns a square matrix of size n where the first and last rows are zeros and the middle rows n are constructed according to the pattern defined in the following examples.
M TriDiagonalMatrix
M ;;
M TriDiagonalMatrix
M ; ;; ;
M TriDiagonalMatrix
M ;;;;;;;;;
Your function must perform the following
Preallocate the output parameter M to the appropriate size.
Use a loop to modify the values in the middle rows n
If the input parameter n is less than assign M a value of NaN.
This is done in MATLAB. This is code I tried earlier but doesn't work according to the test codes I have.
function M TriDiagonalMatrixn
if n
M NaN;
return;
end
M zerosn;
for i :n
Mi i i;
Mi i i;
Mi i i;
end
end
If possible, can you try to include the by by and by matrices inside the code instead of the i notation I used?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started