I need to solve this PDE $$\partial_tf(t,x)+\partial_xf(t,x)+k\partial_{xx}f(t,x)-xf(t,x)=0 $$
with $k\in\mathbb{R}$ and final condition $f(T,x)=1$ with $0<t<T$.
My problem is how to solve numerically this PDE according to this:
$\begin{cases} k=k_1, \quad \partial_{xx}f(t,x) \ge 0 \\k=k_2, \quad \partial_{xx}f(t,x)<0 \end{cases}$
with $k_1,k_2\in\mathbb{R}$.
I supposed WhenEvent
were to be used, therefore I set
T = 1
pde = D[f[t, T, x], {t, 1}] + D[f[t, T, x], {x, 1}] + k*D[f[t, T, x], {x, 2}] -
x*f[t, T, x] == 0
cond = f[T, T, x] == 0
and with NDSolve
sol = NDSolve[{pde, cond,
WhenEvent[D[f[t, T, x], {x, 2}] >= 0, k -> 0.1],
WhenEvent[D[f[t, T, x], {x, 2}] < 0, k -> 0.05]},
f[t, T, x], {t, 0, T}, {x, 0, 0.5}]
but i got this error
NDSolve::ivone: Boundary values may only be specified for one independent variable. Initial values may only be specified at one value of the other independent variable.
ADDED: I pointed out that $f$ is a function only in $t$ and $x$, T
is inserted in the code because it tries to replicate a bond-finance setting. Moreover, removing from the code the WhenEvent
part I got a solution similar to this one: https://mathematica.stackexchange.com/questions/78186/pde-solved-with-ndsolve-how-can-i-plot-the-partial-derivatives-of-the-solution
How can I fix this problem?
f[t, y, x]
orf[t, x]
orf[y, x]
? And you still miss 2 boundary conditions. (A rule of thumb for the necessary number of i.c. or b.c. is that it should be usually equal to the highest order of the corresponding derivative.) $\endgroup$NDSolve
gives an answer currently, it's not that clear what boundary is added. $\endgroup$