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?
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:35Method -> {"MethodOfLines", "DifferentiateBoundaryConditions" -> False}. As to why this works, read this: https://mathematica.stackexchange.com/a/127411/1871 – xzczd Dec 17 '23 at 08:55