I need help please

Hello... everyone
Can anyone help me to find what the mistake in this code?
r0 = 0.03;
theta = 0.10;
k = 0.3;
beta = 0.03;
n = 10;
T = 10;
m = 200 ;
dt = T/m ;
r = zeros(m+1,n) ;
r(1,:) = r0;
for j = 1:n
for i = 2:(m+1)
dr = k*(theta-r(i-1,j) )*dt + beta*sqrt(dt)*randn(1,0,1);
r(i,j) = r(i-1,j);
end
end
t = meshgrid(0, T, dt);
rT.expected = theta + (r0-theta)*exp(-k*t);
rT.stdev = sqrt( beta^2/(2*k)*(1-exp(-2*k*t)));
plot(t,r(1:10));
plot(theta,2);
lines(t, rT.expected, 2) ;
lines(t, rT.expected + 2*rT.stdev, 2 ) ;
lines(t, rT.expected - 2*rT.stdev,2 ) ;
points(0,r0);
thanks;

답변 (2개)

Walter Roberson
Walter Roberson 2015년 11월 23일

0 개 추천

The function lines has to do with creating a colormap that is the same as the current axes ColorOrder . It does not expect any input arguments.
There does not appear to be any MATLAB routine named points()

댓글 수: 5

Alaa
Alaa 2015년 11월 23일
Sorry, can you explain more what should I do?
What do you expect your code line
lines(t, rT.expected, 2) ;
to do?
What do you expect
points(0,r0);
to do?
Stephen23
Stephen23 2015년 11월 23일
편집: Stephen23 2015년 11월 23일
You should learn to read the documentation for every function that you use.
You can easily search the documentation using your favorite internet search engine, and this will also show you what functions actually exist. While it s great to be creative and invent function names, if you actually want your code to work then you need to read the documentation to choose from the supported functions and also know how to use them. The documentation show the syntax, describes the input and outputs, and gives working examples. So you don't need to make things up!
Learning MATLAB starts with reading the documentation, and even experienced users read the documentation because it tells them how to do more complicated stuff. So reading the documentation is a good habit to learn.
Alaa
Alaa 2015년 11월 23일
this is code for the part (b)
Walter Roberson
Walter Roberson 2015년 11월 23일
The code for part (b) of what?
What exactly is the error that you are seeing, the one you want us to pay attention to?
Thorsten
Thorsten 2015년 11월 23일
편집: Thorsten 2015년 11월 23일

0 개 추천

You did not tell us what you want to do, so it is somewhat speculative to propose what you should do. If you want to plot a line of rT vs. t for different t from 0 to T in steps of dt, with two lines spaced +/- 2*stddev apart, you can do the following:
t = 0:dt:T;
rT.expected = theta + (r0-theta)*exp(-k*t);
rT.stdev = sqrt( beta^2/(2*k)*(1-exp(-2*k*t)));
plot(t, rT.expected)
hold on
plot(t, rT.expected+2*rT.stdev)
plot(t, rT.expected-2*rT.stdev)
and to plot a small circle around 0,r0:
plot(0, r0, 'o')

이 질문은 마감되었습니다.

태그

질문:

2015년 11월 23일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by