Question: You may be familiar with the binomial triangle (also called Pascal's triangle). The k^th row of this triangular array of integers contains the coefficients in

You may be familiar with the binomial triangle (also called Pascal's triangle). The k^th row of this triangular array of integers contains the coefficients in the polynomial expansion of (1 + x)^k. Sadly for you, the binomial triangle is old news. This problem is about the trinomial triangle, the first six rows of which are shown below. k = 0; k = 1; k = 2; k = 3; k = 4; k = 5; The k^th row of the trinomial triangle lists the coefficients in the polynomial expansion of f(1 + x + x^2)^k. For example, the k = 3 row tells us that (1 + x + x^2)^3 = 1 + 3x + 6x^2 + 7x^3 + 6x^4 + 3x^5 + x^6. Note that each level from k = 2 onwards satisfies the following conditions: the beginning and ending elements of each row are always 1, the second entry in each row is the sum of 2 elements: the element above and the element above-right, the next-to-last entry in each row is the sum of the 2 elements: the element above and the element above-left; the remaining entries in each row are each the sum of 3 elements: the element above-left, the element above, and the element above-right. Write a Matlab program called tritriagain.m which calculates the sequence of integers on any level of the trinomial triangle, given a nonnegative integer k. If k is not an integer, or is negative, then the function should return the flag value - 1. Program specifications and sample function calls are given below. input parameter k a positive integer output parameter trilist a vector containing the requested level of the trinomial triangle sample function calls tritriagain(2) produces [1, 2, 3, 2, 1] tritriagain(5) produce [1, 5, 15, 30, 45, 51, 45, 30, 15, 5, 1] tritriagain (-5) produces -1 tritriagain (3.872) produces -1 You may be familiar with the binomial triangle (also called Pascal's triangle). The k^th row of this triangular array of integers contains the coefficients in the polynomial expansion of (1 + x)^k. Sadly for you, the binomial triangle is old news. This problem is about the trinomial triangle, the first six rows of which are shown below. k = 0; k = 1; k = 2; k = 3; k = 4; k = 5; The k^th row of the trinomial triangle lists the coefficients in the polynomial expansion of f(1 + x + x^2)^k. For example, the k = 3 row tells us that (1 + x + x^2)^3 = 1 + 3x + 6x^2 + 7x^3 + 6x^4 + 3x^5 + x^6. Note that each level from k = 2 onwards satisfies the following conditions: the beginning and ending elements of each row are always 1, the second entry in each row is the sum of 2 elements: the element above and the element above-right, the next-to-last entry in each row is the sum of the 2 elements: the element above and the element above-left; the remaining entries in each row are each the sum of 3 elements: the element above-left, the element above, and the element above-right. Write a Matlab program called tritriagain.m which calculates the sequence of integers on any level of the trinomial triangle, given a nonnegative integer k. If k is not an integer, or is negative, then the function should return the flag value - 1. Program specifications and sample function calls are given below. input parameter k a positive integer output parameter trilist a vector containing the requested level of the trinomial triangle sample function calls tritriagain(2) produces [1, 2, 3, 2, 1] tritriagain(5) produce [1, 5, 15, 30, 45, 51, 45, 30, 15, 5, 1] tritriagain (-5) produces -1 tritriagain (3.872) produces -1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
