Question

MATLAB save output as array this is my code so far, I'm going to need to...

MATLAB save output as array

this is my code so far, I'm going to need to save these as arrays or vectors i think to take some statistics on them.

how do i save each walkers position relitive to time

I should end up with 1000x 1000 matrix i think

or 1000 arrays

walkers=1000;
%walkers=input('how many walkers do you want to simulate?')

N = 1000;
%N = input('how many steps do you want?')

for k= 1:walkers
displacement= randn(1,N);
x = cumsum(displacement);
plot(x);
ylabel('position');
xlabel('time');
title('Position of walker');
end

i was trying something to the effect of:

for k= 1:walkers
displacement= randn(1,N);
x(k) = cumsum(displacement);
plot(x(k));
ylabel('position');
xlabel('time');
title('Position of walker');
end

but couldnt get it to function correctly

i also need to put a limit to the min and max the "walkers" can go.

Homework Answers

Answer #1

Code :

MATLAB Code:

%walkers=1000;

walkers=input('how many walkers do you want to simulate? :')

%N = 100;

N = input('how many steps do you want? :')

for k= 1:walkers

displacement(k,1:N)= randn(1,N);

x(k,1:N) = cumsum(displacement(k,1:N));

plot(x(k,1:N));

hold on;

ylabel('position');

xlabel('time');

title('Position of walker');

end

OUTPUT:

>> walkers_prog

how many walkers do you want to simulate? :1000

walkers =

1000

how many steps do you want? :1000

N =

1000

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Problem 3 you can use Matlab and also i give u the Problem 1 code its...
Problem 3 you can use Matlab and also i give u the Problem 1 code its on Matlab Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandpass filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce this is the Problem 1 code and the solutin clear; clc;...
what did i do wrong in here? error said I have wrong code for scatter(rate(:,1),rate(:,5),'o') but...
what did i do wrong in here? error said I have wrong code for scatter(rate(:,1),rate(:,5),'o') but when I solved it, other codes are messed up how to solve it? datacell = textscan( regexprep( fileread('cricketData.csv'), '\$', '0' ), '%f%f', 'delimiter', ',', 'HeaderLines', 1); Duration = datacell{1}; Input = datacell{1}; YourTable = table(Duration, Input); temp=datacell(:,1); rate=datacell(:,2); scatter(rate(:,1),rate(:,5),'o') xlabel('temperature(T in degrees Fahrenheit)') ylabel('chirping (R in chirp per second))') title('Chirping rate vs Temperature') p=polyfit(rate(:,1),rate(:,2),1); x=min(1)-2:.01:max(2)+2; hold on plot(x,polyval(p,x)) legend('Data points,''best fit equation') fprintf('Calculated equation:...
Using the following code: % Ex 6.4 First-order step and impulse response for two time constants...
Using the following code: % Ex 6.4 First-order step and impulse response for two time constants % clear all; close all; t = 0:.1:100; % Time vector subplot(1,2,1); x = 250*exp(-0.05*t); plot(t,x,'k'); xlabel('Time (hrs)','FontSize',14); ylabel('P_A (mmHg)','FontSize',14); title('Impulse Response','FontSize',14); subplot(1,2,2); x = 20*(1-exp(-0.05*t)); plot(t,x,'k'); xlabel('Time (hrs)','FontSize',14); ylabel('P_A (mmHg)','FontSize',14); title('Step Response','FontSize',14);    ANSWER: The response of a 1st order linear body fluid balance system to step function (L m (t) = 1/s, Eqn. 6.9/p226) and impulse function (L d (t) = 1,...
Question : Design the low and high pass filter for the signal, x(t) = 10 sin...
Question : Design the low and high pass filter for the signal, x(t) = 10 sin (10 t) + 1 sin (1000 t) by MATLAB Is below answer right? at ?High pass , 5row shouldn't this change from sin(100*t) ? sin(1000*t) x = 10*sin(10*t) + 1*sin(100*t); ?   x = 10*sin(10*t) + 1*sin(1000*t); ??? ..................................................................................................................................................... ?Low pass clc; rng default Fs=2000; t=linspace(0,1,Fs); x=10*sin(10*t)+sin(1000*t)%given signal n=0.5*randn(size(t));%noise x1=x+n; fc=150; Wn=(2/Fs)*fc; b=fir1(20,Wn,'low',kaiser(21,3)); %fvtool(b,1,’Fs’,Fs) y=filter(b,1,x1); plot(t,x1,t,y) xlim([0 0.1]) xlabel('Time (s) ') ylabel('Amplitude') legend('Original Signal','Filtered Data')...
Modify your Free Fall program below to plot the energy vs. time for a baseball dropped...
Modify your Free Fall program below to plot the energy vs. time for a baseball dropped from a height of 1000 feet until it hits the ground. Now add in the effects of air resistance into your program. This time, on the energy plot, you will plot four quantities: KE (Red line), PE (Green line), Energy lost due to air resistance (purple line), and total Energy (blue circles). Note, you must calculate the energy lost by using the definition of...
In this problem you will use the cursor tracker code from the previous homework assignment to...
In this problem you will use the cursor tracker code from the previous homework assignment to measure frequency responses to various sinusoidal inputs and then generate a Bode plot. Use the Matlab file track cursor.m provided on Blackboard for a proportional controller with K = 0.1. After the tracker equilibrates, generate a sinusoidal input by moving the cursor back and forth and determine the gain and phase. The gain is the ratio of the amplitude of the output sinusoid over...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
For this lab assignment you will need to write some code and create some graphs. You...
For this lab assignment you will need to write some code and create some graphs. You may use excel to create your graphs, or other language of your choice. Your data needs to demonstrate the experimental running time for Selection Sort (code in book), Merge Sort (code in book), and the Arrays.sort() method. Here is a basic outline of how you need to code this assignment. 1) Create several arrays of size 100, 1000, 10000, 100000, 1000000, … (you need...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...