A symmetric (5 times 5) Pascal matrix (Google it!) is displayed below. Write a p
ID: 3574459 • Letter: A
Question
A symmetric (5 times 5) Pascal matrix (Google it!) is displayed below. Write a program that creates an n times n symmetric Pascal matrix (avoid using a built-in Matlab function Pascal). Use the program to create 4 times 4 and 7 times 7 Pascal matrices. S_5 = [1 1 1 1 1 1 2 3 4 5 1 3 6 10 15 1 4 10 20 35 1 5 15 35 70] Note: Symmetrical Pascal matrix S can be computed as a product between two matrices: S = L * U, where L and U are matrix exponentials (Matlab function expm) of subdiagonal and superdiagonal matrices of the following form (please note, that the matrices given below are true for the 5 times 5 Pascal matrix): U_5 = [0 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 4 0 0 0 0 0] L_5 = [0 0 0 0 0 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 4 0]The primary objective of this problem is, therefore, boils down to construction of two sub-and super-diagonal matrices of arbitrary order. The rest of the process of construction of the Pascal matrix is reduced to a simple matrix exponentiation and matrix multiplication.Explanation / Answer
Code:
pascal.m file
function A = pascal(N)
n = N;
m = N;
A=[]; % define an empty matrix
for k=1:n
for h=1:m
if k==1
A(k,h)=k;
elseif h==1
A(k,h)=h;
else
A(k,h)=A(k,h-1) + A(k-1,h); %assign values to other elements
end
end
end
end
test.m file
A = pascal(4)
B = pascal(7)
Output:
ans =
1 1 1 1
1 2 3 4
1 3 6 10
1 4 10 20
ans =
1 1 1 1 1 1 1
1 2 3 4 5 6 7
1 3 6 10 15 21 28
1 4 10 20 35 56 84
1 5 15 35 70 126 210
1 6 21 56 126 252 462
1 7 28 84 210 462 924
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.