Matlab Assignment

Attribution Non-Commercial (BY-NC)

10 views

Matlab Assignment

Attribution Non-Commercial (BY-NC)

- lu Bba Syllabus
- Demostraciones de Matrices
- vibration
- Stiffness of Pre Stressed Frameworks by Guest
- IAS Mains Mathematics 2012
- Cryptography
- ASS4RD3901A32
- Week2 activity
- Gonit Sora Pi Day Quiz 2014
- quickref-linalg
- 02 Quiz
- lec18
- Cs602 Mid Term 1 Www.vu786.Com
- Syllabus B. Tech I Year Group-B 2012[1]
- Excerpts from Algebra - An Algorithmic Treatment.pdf
- Robust Face Recognition via Sparse Representation-zz.pdf
- MLatScale
- Amundson's Matrix Method for Binary Distillation Revisited
- D7.4_v20110627_final_online
- exampl c1

You are on page 1of 3

Monte Carlo Methods Random Numbers Random Number Cycle Linear Congruential Generators Multiplicative LCG Mixed LCG

lcg.m this Matlab code implements a comprehensive function LCG(a, c, m, X0) with the following inputs and outputs:

inputs:

outputs:

P period of the sequence mean average of one period of the real random numbers var variance of the sequence of one period of the random numbers one period and three (P+3) integer numbers.

Below is given the Matlab code for the function. Stedents can generate random numbers using different input parameters. function [p, mean, var, oneperiod]=lcg(a, c, m, x) % Linear Congruential Generators % x the initial seed, 0 <= c < m % a the multiplier, 0 <= a < m, normally greater than 1 % c the increment 0 <= c < m % m the modulus, prime numbers are best xseq=x; for j=1:m+5 % generate m+5 integers x= rem((a*x+c),m); % (a*x + c) mod m; xseq=[xseq;x]; % concatenate numbers, in a cloumn row=xseq'; % transpose to a row end

% find out the period i=1; j=2; while row(i) ~= row(j) if j > m % integer row(i) doesnt repeat in the sequence i=i+1; % see if the next integer repeats or not j=i; end; j=j+1; end; p=j-i; % one period of random integer number oneperiod=row(i:i+p+2); % one period and three integers % calculate the real number of a period p r=row(i:i+p-1)/m; % divide by m, so distributed in [0,1) mean = sum(r)/p; % average diff=mean-r; square=diff.*diff; var=sum(square)/p; % variance However, Matlab environment has already predefined functions to generate random numbers: RAND Uniformly distributed random numbers.

RAND(N) is an N-by-N matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0) RAND(M,N) and RAND([M,N]) are M-by-N matrices with random entries RAND(M,N,P,...) or RAND([M,N,P,...]) generate random arrays RAND with no arguments is a scalar whose value changes each time it is referenced RAND(SIZE(A)) is the same size as A

RANDN(N) is an N-by-N matrix with random entries, chosen from a normal distribution with mean zero and variance one. RANDN(M,N) and RANDN([M,N]) are M-by-N matrices with random entries. RANDN(M,N,P,...) or RANDN([M,N,P...]) generate random arrays.

RANDN with no arguments is a scalar whose value changes each time it is referenced. RANDN(SIZE(A)) is the same size as A.

R = SPRAND(S) has the same sparsity structure as S, but uniformly distributed random entries. R = SPRAND(m,n,density) is a random, m-by-n, sparse matrix with approximately density*m*n uniformly distributed nonzero entries. SPRAND is designed to produce large matrices with small density and will generate significantly fewer nonzeros than requested if m*n is small or density is large. R = SPRAND(m,n,density,rc) also has reciprocal condition number approximately equal to rc. R is constructed from a sum of matrices of rank one.

R = SPRANDN(S) has the same sparsity structure as S, but normally distributed random entries. R = SPRANDN(m,n,density) is a random, m-by-n, sparse matrix with approximately density*m*n normally distributed nonzero entries. SPRANDN is designed to produce large matrices with small density and will generate significantly fewer nonzeros than requested if m*n is small or density is large. R = SPRANDN(m,n,density,rc) also has reciprocal condition number approximately equal to rc. R is constructed from a sum of matrices of rank one.

RANDPERM(n) is a random permutation of the integers from 1 to n. For example, RANDPERM(6) might be [2 4 5 6 1 3].

- lu Bba SyllabusUploaded byTalha Siddiqui
- Demostraciones de MatricesUploaded byJohn Bayron Pineda Galeano
- vibrationUploaded byscribactive2010
- Stiffness of Pre Stressed Frameworks by GuestUploaded byTensegrity Wiki
- IAS Mains Mathematics 2012Uploaded byRajkumar
- ASS4RD3901A32Uploaded byAparnesh Roy
- Week2 activityUploaded byYipeng Chamberlain Chu
- 02 QuizUploaded byMuhammad Irfan
- CryptographyUploaded byJaishree Jain
- Gonit Sora Pi Day Quiz 2014Uploaded byWinky
- lec18Uploaded bydani10gherghel
- Syllabus B. Tech I Year Group-B 2012[1]Uploaded byVishesh Sharma
- quickref-linalgUploaded bywoodbrent7
- Cs602 Mid Term 1 Www.vu786.ComUploaded byESNA678
- Excerpts from Algebra - An Algorithmic Treatment.pdfUploaded byf00bar123
- Robust Face Recognition via Sparse Representation-zz.pdfUploaded byAjayaHS
- MLatScaleUploaded bypraneeth8711
- Amundson's Matrix Method for Binary Distillation RevisitedUploaded bybarbara_rope
- D7.4_v20110627_final_onlineUploaded bytariq76
- exampl c1Uploaded bysowhat-01
- A Hw 7 Aralu0131k Mathematics Assignments MatrixUploaded byPamela Bowers
- One-Shot Balancing of Rigid Rotors, A Closed Form Solution - DeTC 2009Uploaded byLasse Hansen
- MATH1902 - Course OutlineUploaded byRoy Lin
- Sharpe - Retirement Income Scenario MatricesUploaded byJulio José
- psu254mho1Uploaded byJohn Le Tourneux
- Santos Et. Al., 2017Uploaded byFernanda Lago
- Matrices and DeterminantsUploaded byAnonymous G4VuCb
- Halfyearlypracticals2018program ListUploaded byG SIVAMKUMAR
- SolSec8pt6.pdfUploaded bychoi
- YesUploaded byMichael Langat

- MTE3105 Pengujian Hipotesis Khi Kuasa Dua 2Uploaded bySitherrai Paramananthan
- Survival AnalysisUploaded byamme_puspita
- Viterbi Decoder for CodingUploaded byAgrakshiMehta
- BootUploaded byJustin Talbot
- Excel Beta ExampleUploaded byMelody Lasrado
- examen 2 courseraUploaded byADQ LOBO
- Physical Layer Design for Packet Data over IS-136Uploaded byhugojdb
- Panel Lecture - GujaratiUploaded byPär Sjölander
- Using ANOVA in Project ReportUploaded byRoyal Projects
- Expected Value of a Symmetric PDFUploaded byTara
- ECE 651 OutlineUploaded byGeorge C Micros
- ThesisUploaded bydaking84
- Investigation STBC on Powerline CommunicationUploaded byA_Sulistyo
- Ee132b Hw9 SolUploaded byDylan Ler
- tema 2 ENGUploaded byXavier Jiménez
- Chapter 5 PowerpointUploaded byAdam Glassner
- MCC 202.docxUploaded byRon Opulencia
- slide teori antrianUploaded byMuhammad Sandilaga
- stt630chap7Uploaded byDxtr Medina
- Descriptive StatisticsUploaded byAndrea Vukic
- Syllabus Stat F10Uploaded bychackblock
- Geostatistical SimulationUploaded bycesarchr
- powerpointUploaded byCamille Pastrana
- Inferential Statistics in Psychology3.docxUploaded byMihaela Filip
- An Introduction to Error Correction ModelsUploaded byrunawayyy
- Young Case Page 397Uploaded byswapniljsoni
- AP Statistics SyllabusUploaded byAndy Nguyen
- lossdistUploaded bybudi626
- Reg ModsUploaded byMANOJ KUMAR
- QTIA ReportUploaded byAli Madad

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.