Results 1 to 2 of 2

Math Help - Stochastic DE's;Eulers Method; MATLAB

  1. #1
    Member Maccaman's Avatar
    Joined
    Sep 2008
    Posts
    85

    Stochastic DE's;Eulers Method; MATLAB

    I have attached a question below that involves MATLAB. I have done most of it although I am unsure of what to do with the underlined question in the attachment.

    here is my matlab code for anyone with matlab:

    function y = stochde1
    % This section generates White Noise
    randn('state',0);
    T = 1; N = 2^(18); h = T/N;
    w=randn(N,1);
    W = [0 ; cumsum(w)*sqrt(h) ];
    t=(0:N)'*h;

    % Develops solution to the CIR model for this particular W
    % using Euler's Method at N = 2^18

    kappa = (1/5); rbar = 6.8; beta =(1/5); p=(1/2);
    r = nan +zeros(N+1, 1);
    r(1) = 7.8;
    for i=1:N
    r(i + 1) = r(i) - kappa*(r(i)-rbar)*h + r(i)^p*beta*(W(i+1)-W(i));
    end
    rw = r;
    plot( t,W,'-r', t, rw,'b'), title('White Noise Path(Red), the Interest Rate Path It Generates using N=18(blue), and the Interest Rate Path It Generates using N=4(green) ')
    hold on;
    clear N T h w W t
    %This section develops solution to the CIR model for this particular W
    % using Euler's method at N=4

    randn('state',0);
    T = 1; N = 4; h = T/N;
    w=randn(N,1);
    W = [0 ; cumsum(w)*sqrt(h) ];
    t=(0:N)'*h;
    r = nan +zeros(N+1, 1);
    r(1) = 7.8;
    for i=1:N
    r(i + 1) = r(i) - kappa*(r(i)-rbar)*h + r(i)^p*beta*(W(i+1)-W(i));
    end
    rw = r;
    plot( t, rw,'g')

    % To calculate the error r^w_n - r^w



    % Summarises Results in a Excel Spreadsheet
    A = [t(1) t(2) t(3) t(4) t(5);W(1) W(2) W(3) W(4) W(5)];
    B= {'Value of t'; 'Value of W(t)';}
    wk1write('Question 1 (a).wk1', A, 0,0);
    M = wk1read('Question 1 (a).wk1');
    xlswrite('Question 1 (a)', M, 'B2:F3');
    xlswrite('Question 1 (a)', B, 'A2:A3');


    This will create a spread sheet and a plot of the W(0), W(1/2), .....ect values in the underlined question. The spread sheet is also attached so you can see the values.

    Can anyone help me work out the error here?
    Last edited by Maccaman; September 9th 2008 at 01:15 AM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member Maccaman's Avatar
    Joined
    Sep 2008
    Posts
    85
    I thought Id add the values for  r^w for N=4

     r^w =

    7.8
    7.62919122274664
    7.12768075689546
    7.14475758313631
    7.20441468871549

    Also is the error  r_n^W - r^W the global error? If so would I just accumulate the local errors (i.e. at W(0), W(1/2), ect)?
    Last edited by Maccaman; September 9th 2008 at 12:50 AM.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Eulers Method
    Posted in the Calculus Forum
    Replies: 4
    Last Post: November 12th 2011, 02:36 AM
  2. eulers method with excel...
    Posted in the Math Software Forum
    Replies: 4
    Last Post: May 19th 2011, 03:42 AM
  3. Eulers Method Question
    Posted in the Differential Equations Forum
    Replies: 1
    Last Post: January 27th 2010, 10:53 PM
  4. eulers method...
    Posted in the Differential Equations Forum
    Replies: 1
    Last Post: March 4th 2009, 05:09 PM
  5. Eulers method fo dif eq..
    Posted in the Calculus Forum
    Replies: 1
    Last Post: March 7th 2008, 08:03 AM

Search Tags


/mathhelpforum @mathhelpforum