## Trending News

# how do you create a pascal matrix in matlab without the built in function?

I have been given the equation Pij = (i + j - 2)!/(i - 1)!(j - 1)! and I need to write a program that will create an n x n symmetric pascal matrix (that will prompt the user for n) without using matlabs build-in function.

Thanks

### 3 Answers

- MichaelLv 49 years agoFavorite Answer
Well the conventional way is to do it with while or for loops, however since matlab works so quick with matrices and vectors I decided to show you another approach. Treat i and j as matrices, and perform matrix operations on them. The variable 'i' will be a matrix of all the row numbers, and the variable 'j' will be the column numbers. The factorial function will perform the element by element factorial, so its a pretty simple problem. The program is below.

%Matlab Code:

%Prompt user for matrix size 'n'

n = input('Enter size of pascal matrix. \n');

%Initialize vector from 1 to n. Use to compute i,j

a = 1:n;

%Create j (The column numbers)

j = ones(n,1)*a;

%Flip j to create i (The row numbers)

i = j';

%Calculate Pij = (i + j - 2)!/(i - 1)!(j - 1)!

p = factorial(i + j - 2)./(factorial(i - 1).*factorial(j - 1));

%Echo p

p

- Anonymous5 years ago
Try to come up with something that is the exact opposite of this! ~ : ) The best drink in existence According to The Hitchhiker's Guide to the Galaxy, the best drink in existence is the Pan Galactic Gargle Blaster; it says that the drink's effect is similar to having one's brains smashed out by a slice of lemon wrapped around a large gold brick. The Pan Galactic Gargle Blaster has also been described in the novel as the alcoholic equivalent to a mugging: expensive and bad for the head. [edit] Original fictional recipe The Pan Galactic Gargle Blaster was invented by Zaphod Beeblebrox, a major character in the series. Its original, fictional, recipe is: Take the juice from one bottle of that Ol' Janx Spirit. Pour into it one measure of water from the seas of Santraginus V Allow three cubes of Arcturan Mega-gin to melt into the mixture (it must be properly iced or the benzene is lost). Allow four litres of Fallian marsh gas to bubble through it (in memory of all those happy Hikers who have died of pleasure in the Marshes of Fallia). Over the back of a silver spoon float a measure of Qualactin Hypermint extract, redolent of all the heady odours of the dark Qualactin Zones. Drop in the tooth of an Algolian Suntiger. Watch it dissolve, spreading the fires of the Algolian suns deep into the heart of the drink. Sprinkle Zamphour. Add an olive. Drink...but very slowly.

- 5 years ago
write the following program in the script file:

clear all

clc

n=input( please entre the size of pascal matrix );

for i=1:n

for j=1:n

P(i,j) = factorial(i+j-2) / (factorial(i-1) * factorial(j-1));

end

end

P

run the file and you are there :) good luck