MATLAB: How to write such an equation on Matlab

equationhistogramstandard deviation

Hello everyone,
I need to know how to write such an equation on Matlab, and define what is x(t) before computing it:
Furthermore, how can I get the distribution of x(50), plot its histogram and compute its standard deviation?
Thank you in advance.

Best Answer

i am not implementing your homework, i am just put the code in the right order so that it looks like you wanted it to do in the way your showed me so far. To me it still looks like this code probably isnt the monte carlo simulation, but that might be your homework to figure out how it works.
function [x_t] = x(t) % you call the function with x(anyvalue) to get x_t
% if you saved it as x.m in the current folder
% define the number of simulations
Nsim= 10000; %%====== is unused
% extract values from epsilon
% epsilon is distributed as a standard normal
N = 10000; %======= shouldnt be this the same as your n /or x?
u=unifrnd(0,1,N,1);
epsilon=norminv(u,0,1);
%define the variables
% n=25; % not needed anymore
% x_t=0;
x_t1=0; % x_t-1
x_t2=1; % x_t-2
for i=1:t
x_t = x_t1 -0.01* x_t2 + 0.1* x_t1* epsilon(i);
x_t2 = x_t1;
x_t1 = x_t;
end
end
type
x(50)
in your command window to get x_50