Question
coding in Matlab Function Name: pascalsPodium Inputs: 1. ( double ) The number of rows to include in your output Outputs: 1. (double) An array
coding in Matlab
Function Name: pascalsPodium
Inputs:
1. ( double ) The number of rows to include in your output
Outputs:
1. (double) An array representing the podium
Banned Functions:
nchoosek(), pascal()
Background:
You have been hired by the International Olympic Committee to design the closing ceremonies. You and your team have all the flower bouquets picked out, ordered the medals, and purchased all the streamers and confetti, but still have one extremely important task: designing the podium. Reminiscing back to high school calculus, you remember learning about Pascals triangle and decide it would be the perfect starting point to constructing the Olympic podium. However, mapping out rows and rows of blocks to recreate Pascals triangle can be tedious, so you choose to use your amazing MATLAB skills to do it for you.
Function Description:
Given the number of rows of Pascal's triangle to include in your final output, build a double array containing the triangle, with zeros filling the spaces in between. For example, the first four rows of Pascal's triangle are usually written in the following fashion:
1
1 1
1 2 1
1 3 3 1
Since the rows of the triangle are offset from one another, our MATLAB representation of the triangle will include zeros to fill the gaps. So we can show the first four rows of the triangle as the following 4x7 double array:
0 | 0 | 0 | 1 | 0 | 0 | 0 |
0 | 0 | 1 | 0 | 1 | 0 | 0 |
0 | 1 | 0 | 2 | 0 | 1 | 0 |
1 | 0 | 3 | 0 | 3 | 0 | 1 |
Each row of Pascal's triangle is constructed by summing adjacent elements of the row above it. For example, to find the value of a certain position, go to the position directly above it (the previous row) and sum the values directly to the right and left of it.
Given this, you can create the array by starting with the first row (it will always be a single 1 in the center of the row), and iterating through the rest of the rows, using the elements of the previous row to create each subsequent row.
Notes:
Inputs to this function will be integers greater than 1.
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