Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help me for this code! PDE

  1. Jul 19, 2009 #1
    I make a pricing model as the attachment and write the code as the following,but there are something wrong in the result.Who could help me to check it?!
    Thx so much!!!!!!!!!!!!!!!
    View attachment Microsoft Word .doc
    the code:
    >> dr = 0.005;
    Nr = 20;
    dt = 0.01;
    Nt = 1/dt;
    a=0.2339*0.0189;
    b=0.2339;
    delta=sqrt(0.0073);
    T = zeros(Nr+1,Nt+1);
    time = [0:12/Nt:12];
    T(:,1) = 1;
    maxiter = 500
    for iter = 1:maxiter
    for i=2:Nt+1

    T(1,i)=(1-a*dt/dr)*T(1,i-1)+(a*dt/dr)*T(2,i-1);
    for j=2:Nr
    %depth_2D = (T(1:end-2,i-1)-2*T(2:end-1,i-1)+T(3:end,i-1))/dz^2;
    depth_2D = (delta^2/(2*dr^2)*dr*(j-1)+((a-b)*dr*(j-1))/(2*dr))*T(j-1,i-1)-(delta^2/(dr^2)*dr*(j-1)+dr*(j-1))*T(j,i-1)+(delta^2/(2*dr^2)*dr*(j-1)+((a-b)*dr*(j-1))/(2*dr))*T(j+1,i-1);
    time_1D = depth_2D;
    T(j,i) = time_1D*dt + T(j,i-1);
    end
    T(Nr+1,i) = T(Nr+1-1,i);

    end
    %end
    err(iter) = min(abs(T(:)-0.5)); %Find difference between last two solutions
    if err(iter)<1E-4
    break; % Stop if solutions very similar, we have convergence
    end
    end
    if iter==maxiter;
    warning('Convergence not reached')
    end
     
    Last edited: Jul 19, 2009
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Help me for this code! PDE
  1. Help With PDE (Replies: 1)

  2. Help on PDE (Replies: 3)

  3. Help with this PDE (Replies: 1)

Loading...