Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Pascal\'s triangle can be displayed as elements in a lower-triangular matrix

ID: 3588550 • Letter: T

Question

The Pascal's triangle can be displayed as elements in a lower-triangular matrix as shown below for 6 rows of Pascal's triangular matrix Write a MATLAB program that creates a n× n matrix that displays n rows of Pascal's triangle. The program must prompt the user to enter the number n of rows in the lower triangular matrix and then create the matrix. (One way to calculate the value of the elements in the lower portion of the matrix is (j-1)(i-j)! 1 5 10 10 5 1 Use the program to create 4 and 7 rows Pascal's triangles. You can use the built-in function factorial ) in MATLAB. Only the Pascal's triangular matrix (PT) must be displayed in the Command Window. Do Not Use disp or fprintf in your program.

Explanation / Answer


n = input('Enter value for n: ');
% If only two rows are requested, then exit
if n < 3
return
end
tr(1, 1) = 1;
tr(2, 1 : 2) = [1 1];
for r = 3 : n
  
tr(r, 1) = 1;   

  
for c = 2 : r-1
tr(r, c) = tr(r-1, c-1) + tr(r-1, c);
end   

  
tr(r, r) = 1;
end
tr

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote