Question

In: Computer Science

Generate the first ten rows of Pascal triangle using MATLAB. Post code in the response

Generate the first ten rows of Pascal triangle using MATLAB. Post code in the response

Solutions

Expert Solution

MATLAB Code to generate first ten rows of Pascal traingle :

function pt = pascal_triangle(n) 

% first two rows of pascal traingle are constant
pt(1, 1) = 1;
pt(2, 1 : 2) = [1 1]; 

% If less or equal to 2 rows are requested, then we already created them and hence return.
if n < 3
    return
end 

for r = 3 : n
    % first element is 1
    pt(r, 1) = 1;   

    % In pascal triangle every element is the addition of the two elements
    % present on  the top of it. 
    for c = 2 : r-1
        pt(r, c) = pt(r-1, c-1) + pt(r-1, c);
    end   

    % last element of each row is 1
    pt(r, r) = 1;
end

end

EXAMPLE :


INPUT: first ten rows of pascal triangle

OUPTUT :   ( NOTE :  The zeros which appears in the ouput occurred naturally when we changed the row in our MATLAB program )


Related Solutions

draw the vertexes of a triangle and generate a list of the vertices code is in...
draw the vertexes of a triangle and generate a list of the vertices code is in python use turtle graphics
In this question using c++, you have to design the Pascal triangle where you can create...
In this question using c++, you have to design the Pascal triangle where you can create a list of coefficients of a binomial of any size that is passed to the constructor. Data members and member functions of this class are of your design choice. You need to use only pointers and pointers to pointers (do not use regular array notations). Create a two-dimensional array in the heap memory (which creates a dynamic memory). Use an application program to print...
Using Matlab, write code to generate Three signal components We will use a sum of sinusoids,...
Using Matlab, write code to generate Three signal components We will use a sum of sinusoids, all of which are sampled at 10 kHz. Signal 1 should contain a sum of sinusoids with frequencies at 25Hz, 40Hz and 75Hz. Signal 2 should contain a sum of sinusoids with frequencies at 600Hz, 730Hz, and 800Hz. Signal 3 should contain a sum of sinusoids with frequencies at 3500Hz, 4000Hz, and 4200Hz. Choose a variety of amplitudes and phase shifts for the sinusoids....
the language is matlab 1) Write a code that will print a list consisting of “triangle,”...
the language is matlab 1) Write a code that will print a list consisting of “triangle,” “circle,” and “square.” It prompts the user to choose one, and then prompts the user for the appropriate quantities (e.g., the radius of the circle) and then prints its area. If the user enters an invalid choice, the script simply prints an error message. For calculating the area, create separate functions for each choice. Name them as calcTriangle, calcCircle, calcSquare respectively, which are only...
Using Matlab code, solve the following: (a) Consider first the undamped pendulum ? + sin ?...
Using Matlab code, solve the following: (a) Consider first the undamped pendulum ? + sin ? = 0, ?(0) = 0, ? (0) = b. Let x = ? and y = ? ; then x and y satisfy the system x = y y = ? sin x, x(0) = 0 y(0) = b. Solve this system numerically and plot, on a single graph, the resulting trajectories for the initial velocities b = 0.5, 1, 1.5, 2, 2.5. Use...
Plot all four curves over 0 < t < 4 together using MATLAB. Post code in...
Plot all four curves over 0 < t < 4 together using MATLAB. Post code in the response. C1 : x=−5+2e−tcos20t y=−5+2e−tsin20t z=4t C2 : x=−5+2e−tcos20t y=5+2e−tsin20t z=4t C3 : x=5+2e−tcos20t y=−5+2e−tsin20t z=4t C4 : x=5+2e−tcos20t y=5+2e−tsin20t z=4t
Write a three.js/HTML programming to generate a Sierpenski Triangle using recursion (generate until 10 depth of...
Write a three.js/HTML programming to generate a Sierpenski Triangle using recursion (generate until 10 depth of recursion) Need the index code with it too so I am able to run it Example of triangle below:
Write a three.js/HTML programming to generate a Sierpenski Triangle using recursion (generate until 10 depth of...
Write a three.js/HTML programming to generate a Sierpenski Triangle using recursion (generate until 10 depth of recursion) Need the index code with it too so I am able to run it
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a sinusoid wave having two components as f1 = 3kHz and f2 = 5kHz and then sample it with fs = 10kHz. Calculate its fft with zero frequency component in the middle. Plot it on a properly scaled w-axis. Specify if there is aliasing or not? If there is aliasing specify which component is casing the aliasing
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT