Untitled

mail@pastecode.io avatar
unknown
matlab
2 years ago
481 B
2
Indexable

//Exo3

//q1
function  R=B(NP,N)  
R=zeros(NP,N+1);
for k=1:NP
   for i=2:N+1
      R(k,i)=R(k,i-1) + sqrt(1/N)*grand(1,1,"nor",0,1);
   end
end
endfunction

R=B(3,1000)
plot(R')

//q2
function  R=X_3(NP,N,mu,sigma)  
R=zeros(NP,N+1);
for k=1:NP
   for i=2:N+1
      R(k,i)=R(k,i-1)*exp((mu-(sigma**2))/2) + sigma*(B(NP,N)-B(NP,N-1));
   end
end
endfunction

//x0=20
//sigma=0.7
//N=1000
R=X_3(3,1000,0,0.7)
plot(R')
S=X_3(3,1000,-1.5,0.7)
plot(S')
T=X_3(3,1000,1.5,0.7)
plot(T')