1
r = 0.04;
v1 = 0.25;
v2 = 0.1;
sigma = Sqrt[v1 + v2];
NDSolve[{D[f[t, x], t] + 0.5 (v1 + v2) x^2 D[D[f[t, x], x], x] - 
    r f[t, x] + r x D[f[t, x], x] == 0, f[t, 0.] == Exp[-r (1. - t)], 
  f[t, 1.] - Derivative[0, 1][f][t, 1.] == 0., 
  f[1., x] == 1. - x}, f, {t, 0., 1.}, {x, 0., 1.}]


u[t_, x_] := 
  N[(1 + (sigma^2)/(2*r)) x CDF[
      NormalDistribution[], (1/(sigma*Sqrt[(1 - t)]))*(Log[
          x] + (r + 0.5*sigma^2)*(1 - t))] + 
    Exp[-r*(1 - t)]*
     CDF[NormalDistribution[], -(1/(sigma*Sqrt[(1 - t)]))*(Log[
          x] + (r - 0.5*sigma^2)*(1 - t))] + (-sigma^2/(2*r))*
     Exp[-r*(1 - t)]*x^(1 - 2*r/(sigma^2))*
     CDF[NormalDistribution[], -(1/(sigma*Sqrt[(1 - t)]))*(Log[
          1/x] + (r - 0.5*sigma^2)*(1 - t))] - x];

I am verifying the theoretical solution u of f, and I am getting the error message "NDSolve: boundary and initial conditions are inconsistent". Why is this happening?

David G. Stork
  • 41,180
  • 3
  • 34
  • 96
Yilin Cheng
  • 109
  • 5
  • As mentioned in the message, "NDSolve: boundary and initial conditions are inconsistent." The inconsistency can be easily verified by solf[1, x_] := 1. - x; f[t, 1.] - Derivative[0, 1][f][t, 1.] == 0. /. t -> 1 /. f -> solf. Please read the document for the warning message carefully for more info. – xzczd Dec 17 '23 at 08:35
  • Thank you very much. I found that there is a problem with my boundaries. This is about the PDE for lookback option pricing, where the boundary condition is: f[t, 1.] - Derivative[0, 1][f][t, 1.] == 0. The range of t in this equation is [0,1). Could you please advise me on how to modify the code to restrict the range of t to [0,1)? – Yilin Cheng Dec 17 '23 at 08:48
  • “solf[1, x_] := 1. - x; f[t, 1.] - Derivative[0, 1][f][t, 1.] == 0. /. t -> 1 /. f -> solf. ” I can not understand, this is modify the code to restrict the range of t to [0,1)? – Yilin Cheng Dec 17 '23 at 08:51
  • 1
    The code in my last comment is for showing you the i.c. and b.c. is indeed inconsistent. As to how to fix the problem you're facing, the easiest solution is Method -> {"MethodOfLines", "DifferentiateBoundaryConditions" -> False}. As to why this works, read this: https://mathematica.stackexchange.com/a/127411/1871 – xzczd Dec 17 '23 at 08:55
  • Ok,Thank you very much. According to your code, I have successfully generated the function plot. – Yilin Cheng Dec 17 '23 at 09:21

1 Answers1

7

Why is this happening?

You say that f[1,x]==1-x which means at time t=1 and for any x, then f=1-x. Lets take x=1 for example. This means at time t=1 then f must zero when x=1.

Next you say f[t,1]==(D[f[t,x],x]/.x->1) But f[1,x]==1-x. Taking derivative w.r.t. x gives -1. Which means f[t,1]=-1

So we have f=-1 at time t=1 when x=1

and

we also have f=0 at time t=1 when x=1.

This is inconsistent.

Nasser
  • 143,286
  • 11
  • 154
  • 359