1
$\begingroup$

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}]
$\endgroup$
  • $\begingroup$ Do not use E, K - Built-in Symbols. $\endgroup$ – Alex Trounev Mar 7 '19 at 16:51
  • 1
    $\begingroup$ Here is the hyperbolic equation, the slope of the characteristic changes sign on the left and right border. Therefore, it is necessary to put two boundary conditions. $\endgroup$ – Alex Trounev Mar 7 '19 at 16:57
  • $\begingroup$ It's necessary to provide b.c. in r0 direction when solving the problem numerically. Related: mathematica.stackexchange.com/q/73961/1871 scicomp.stackexchange.com/q/28744/5331 $\endgroup$ – xzczd Mar 8 '19 at 6:54
  • $\begingroup$ Many thanks! This means that a boundary condition must be defined as a function of t? Can I choose any r0 to define this function ? Are there any other ways to find a b.c? $\endgroup$ – Øyvind Foshaug Mar 8 '19 at 9:30
  • $\begingroup$ I believe this article gives me guidance: link $\endgroup$ – Øyvind Foshaug Mar 8 '19 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.