0% found this document useful (0 votes)
51 views1 page

Code PDF

The document initializes a vector x of length 50 with values of 0 except for x(1)=100 and x(50)=0. It then runs a simulation over 2001 timesteps where at each step and location i, a random number r is generated and if r=1, x(i) decreases by 1 and x(i-1) increases by 1, while if r=2, x(i) decreases by 1 and x(i+1) increases by 1. After the simulation, it plots the resulting vector x against a vector of integers from 1 to 50.

Uploaded by

Suyash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views1 page

Code PDF

The document initializes a vector x of length 50 with values of 0 except for x(1)=100 and x(50)=0. It then runs a simulation over 2001 timesteps where at each step and location i, a random number r is generated and if r=1, x(i) decreases by 1 and x(i-1) increases by 1, while if r=2, x(i) decreases by 1 and x(i+1) increases by 1. After the simulation, it plots the resulting vector x against a vector of integers from 1 to 50.

Uploaded by

Suyash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

9/18/19 10:47 AM \\engin-labs.m...\Untitled.

m 1 of 1

x = zeros(1,50);
x(1) = 100;
x(50) = 0;
Prob = [0 0 1 2];

for t = 0:2000
for i = 1:50
for k = 1:x(i)
r = randi([0 2],1,1);
if r == 1
x(i) = x(i)-1;
if i==1
x(i) = 100;
else x(i-1) = x(i-1)+1;
end
end
if r == 2
x(i) = x(i)-1;
if i == 50
x(i) = 0;
else x(i+1) = x(i+1)+1;
end
end
end
end
end
a = zeros(1,50)
for b = 1:50
a(b) = b;
end
x(1) = 100;
plot(a,x);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy