I cannot find out where the difference comes from.
First pde, solBM30, has variable boundary condition which I evaluate at a certain point. The second pde, solBM32 is identical, except it has a fixed boundary condition which is then evaluated at the same point. The results should be equal right?
σ = 0.;
K = 110;
S = 20;
E = 10;
θ = 0.000023637253287033743;
κ = 0.008622227075117428;
cr = -0.00024031738413887727;
small = 0.01;
solBM30 =
NDSolve[
{D[F[r0, t], {t}] == (-(θ - κ r0)) D[F[r0, t], {r0}], F[r0, K] == 10000 r0},
F, {t, 0, K}, {r0, cr - small, cr + small}];
solBM32 =
NDSolve[
{D[W[r0, t], {t}] == (-(θ - κ r0)) D[W[r0, t], {r0}], W[r0, K] == 10000 cr},
W, {t, 0, K}, {r0, cr - small, cr + small}];
(*Plot[slice[r0],{r0,rd,ru}]*)
F[cr, 0] /. solBM30
W[cr, 0] /. solBM32
Edit: Added the 'full' PDE. Now I get another error.
solBM1 = NDSolve[{0 ==
0.5*σ^2*D[V[r0, t], {r0}, {r0}] + (θ - κr0)*
D[V[r0, t], {r0}] - r0*V[r0, t] + D[V[r0, t], {t}],
V[r0, K] ==
1, (D[V[r0, t], {t}] + θ*D[V[r0, t], {r0}] /. r0 -> 0) ==
0}, {V},
{t, 0, K}, {r0, cr - small, cr + small}]
Edit2:
r1 = -0.000240317
M = 111;
si = 0.000212693;
b = 0.00862223;
a = 0.0000236373;
R = 1/10;
eq = 0 == 0.5*si^2*D[u[t, x], {x, 2}] + (a - b*x)*D[u[t, x], x] -
x* u[t, x] - D[u[t, x], t];
ic = u[0, x] == 1 ;
bc = {(-D[u[t, x], {t}] + a*D[u[t, x], {x}] /. x -> 0) == 0,
u[t, R] == Exp[-R*t]}
domain = {0, R};
difforder = 4;
points = 25;
grid = Array[# &, points, domain];
(*Definition of pdetoode isn't included in this post,please find it \
in the link above.*)
ptoofunc = pdetoode[u[t, x], t, grid, difforder];
removeredundant = #[[2 ;; -2]] &;
ode = removeredundant@ptoofunc@eq;
odebc = ptoofunc@bc
odeic = ptoofunc@ic;
tend = M;
sollst = NDSolveValue[{ode, odeic, odebc}, u /@ grid, {t, 0, tend}];
sol = rebuild[sollst, grid];
Plot3D[sol[t, x], {t, 0, tend}, {x, ##}] & @@ domain
Edit3 (Beware I corrected a mistake in the first b.c in edit2 ):
vas[t_, r0_] = a/b + (r0 - a/b)*Exp[-b*t];
B[t_, T_] := (1 - E^(-b (T - t)))/b
A[T_, t_] := (a/b - si^2/(2 b^2)) (B[t, T] - (T - t)) - (
si^2 B[t, T]^2)/(4 b)
Z1[t_, T_] := E^(A[T, t] - 0*B[t, T])
Z2[t_, T_] := E^(A[T, t] - vas[t, 0] B[t, T])
Plot[{sol[M - t, 0], Z1[t, M], Z2[t, M]}, {t, 0, M}]
E, K- Built-in Symbols. – Alex Trounev Mar 07 '19 at 16:51r0direction when solving the problem numerically. Related: https://mathematica.stackexchange.com/q/73961/1871 https://scicomp.stackexchange.com/q/28744/5331 – xzczd Mar 08 '19 at 06:54NDSolvecannot handle the b.c. atr0==0, so we need to discretize the equation all by ourselves,pdetoodecan be used for the task. – xzczd Mar 08 '19 at 15:32R=1/10to defineR,MachinePrecisionnumber can cause trouble becausepdetoodecurrently uses===to check if an equation is on the boundary. (Well, perhaps I should re-design this part. ) 2.domainshould bedomain={0,R}. 3.difforderis short for difference order i.e. it's the order of the difference formula used for discretization.pdetoode, now it can handle definition likeR=0.1properly. – xzczd Mar 24 '19 at 03:29Z1andZ2, butZ1is wrong and the numeric solution is the same asZ1? If so, the only thing I know at this point is, I believe the numeric solution is reliable enough, if it doesn't match the analytic solution, you should check whether same problem is solved or not. – xzczd Mar 25 '19 at 05:27(D[u[t, x], {t}] /. x -> 0)==0orD[u[t, x], {t}] ==0/. x -> 0. – xzczd Mar 25 '19 at 16:42