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

You may be familiar with the binomial triangle (also called Pascal\'s triangle).

ID: 3575069 • Letter: Y

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 the polynomial expansion of (1 + x)^k. Sadly for you the binomial triangle is old news. This problem is about the trinomial trim the first six rows of which are shown below. The k^th row of the trinomial triangle lists the coefficients, in the polynomial expansion of of (1 + x + x^2). 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 triter again which calculates the sequence of integers on any level of the trinomial given a nonnegative integer k. Program specification and sample function calls are given below. input parameter k a positive integer output parameter trollist a vector containing the requested level of the trinomial tringle

Explanation / Answer

Program contains two parts. first funtion file and second main script file.

in our case funtion name is trilist so filename will be trilist.m because it's matlab syntax.

Save following code in trillist.m file

Begin code:

function x = trilist(k)
if ((k < 0) || (k != floor(k)))
x = -1;
else
base = [1,1,1]
if (k == 1)
x = [1]
elseif(k == 2)
x = base
else
tmp = base
for i = k-2:-1:0
base = tmp;
tmp = [1] %first entry on any level
add = base(1)+base(2); %second entry on level
tmp = [tmp, add];
for in = 2:length(base) - 1
add = base(in-1) + base(in) + base(in+1);%all other element of level
tmp = [tmp add]
end
ln = length(base)
add = base(ln)+base(ln-1);
tmp = [tmp, add];% second last entry in level
tmp = [tmp 1] %last entry on any level
end
x = tmp;
end
end
end

Code end:

Now paste follwing code in main.m file. (make sure both file trilst.m and main.m are in same directory)

Begin code:

level = input('Enter level');
result = trilist(level)
disp(result);

Code end.

and comes the execution of main file. run commad based on style your installation of matlab.

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