How do you create a pascal matrix in matlab without the built in function?
-
-
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
Yoda at Yahoo! Answers Visit the source
Other answers
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
Michael
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.
Gloria
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
Nadia
Related Q & A:
- How do I create a Cocoa Touch Framework?Best solution by stackoverflow.com
- How to dynamically create a PHP class name on the fly?Best solution by stackoverflow.com
- how to Create a Java Package from MATLAB Code?Best solution by Stack Overflow
- How do I create a digital signature and how do I use it?Best solution by support.office.com
- How do you change a ford ranger key cylinder without a key?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.