I am unsure how to store the values, then take the average, from my output St into a large matrix so that I can work with the numbers more easily. I have looked through other responses, and cant seem to find a solution. The code is as follows. Any help is greatly appreciated.

댓글 수: 1

Stephen23
Stephen23 2018년 3월 29일
@Quinn Hayward: we cannot run a screenshot, we cannot edit a screenshot, we cannot search a screenshot, we cannot use a screenshot. Screenshots as basically useless as a way of giving us your code. If you want help then please delete the screenshot and give your code as text.

댓글을 달려면 로그인하십시오.

 채택된 답변

Rik
Rik 2018년 3월 29일

0 개 추천

Please, never post your code as an image. It actively discourages people to help, because we can't copy and paste code to fix it. The code below should be something like what you mean.
Pay attention to the m-lint warnings. They alert you to potential bugs and possible places to improve your code. Use functions to keep your workspace clean (or at least consider using clearvars instead), and don't use clc if you're not planning on using disp or fprintf.
mu=0.004;
sigma=0.05;
S1=72;
N=261;
K=5;
dt=sigma/sqrt(N);
M=zeros(N,K);
for k=1:K
St=zeros(N,1);St(1)=S1;
for i=2:N
epsilon=randn;%don't overwrite the internal eps function
St(i)=St(i-1)+St(i-1)*(mu*dt+sigma*epsilon*sqrt(dt));
end
M(:,k)=St;
end
plot(M)
xlim([1 N])
xlabel('days')
ylabel('value')

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2018년 3월 29일

답변:

Rik
2018년 3월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by