Why do I get an error in this function and how to solve it?
1 view (last 30 days)
Show older comments
function r=OU_SAMPLE (n,dt,beta,theta,sig,r0);
t(1)=0;
x(1)=theta-r0;
r(1)=r0;
for i=1:n-1;
t(i+1)=i*dt;
v=(exp(2*beta*t(i+1))-exp(2*beta*t(i)))*(2*beta)^(-1);
x(i+1)=x(i)-sig*normrnd(0,sqrt(v));
r(i+1)=theta-exp(-beta*t(i+1))*x(i+1);
end;
end
function r=OU_SAMPLE (n,dt,beta,theta,sig,r0);
↑
Error: Function definition not supported in this context. Create functions in code file.
0 Comments
Accepted Answer
the cyclist
on 29 Apr 2021
You cannot define a function at the command line. You need to place the lines
function r=OU_SAMPLE (n,dt,beta,theta,sig,r0);
t(1)=0;
x(1)=theta-r0;
r(1)=r0;
for i=1:n-1;
t(i+1)=i*dt;
v=(exp(2*beta*t(i+1))-exp(2*beta*t(i)))*(2*beta)^(-1);
x(i+1)=x(i)-sig*normrnd(0,sqrt(v));
r(i+1)=theta-exp(-beta*t(i+1))*x(i+1);
end;
end
inside of a file (that conventionally should be named OU_SAMPLE.m).
Then you can call that function using
OU_SAMPLE() % with the appropriate arguments
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!