Coefficients in the expansion of (x+y)^n form a pattern which is useful for small values of n. It is known as Pascal's triangle.
n Pascal's triangle
1 1 1
2 1 2 1
3 1 3 3 1
4 1 4 6 4 1
5 1 5 10 10 5 1
Write a Matlab script to calculate and display this expression in the form of the triangle for the first 10 values of n. Use the sprintf command to display in a suitable format such as that shown above.
% A Program for Pascal's Triangle
if nargin ~=2
n=1:10;
s=4;
end
if n<55
a= n/10;
x=0;
y=0;
x2=0;
w=1;
hold on;
for m = 1:n-1
x = x2-a/2;
y = y-a/2*sqrt(2);
w = 1;
x2 = x;
for l = 1:m
x = x+a;
w = nchoosek(m,1);
end
end
else clf;
text(-0.2,0.5,' FontSize',23);
end;
hold off;
axis square;
axis equal;
axis off;
I had tried the question but i am not getting through it can any1 help me out in this problem.