0
$\begingroup$

I am trying to achieve two things. The first thing is I want to define a function in Mathematica which is the solution of a PDE. A simple example:

sol := NDSolve[{D[f[x,y],x,y] == 2*x*y, f[0,y] == 0, f[x,0] == 0}, f,{x, 0, 10}, {y, 0, 10}] g[x_,y_] := f[x,y] /. sol 

But this doesn't work and I don't know why.

The second thing is, I want to solve a PDE with NDSolve which involves the derivative of a solution of another PDE. For example

 sol := NDSolve[{D[f[x,y],x,y] == D[g[x],x] * y, D[g[x],{x,2}] == 2, g[0] == 0, f[0,y] == 0, f[x,0] == 0}, f,{x, 0, 10}, {y, 0, 10}] 

Does anyone know how to do that?

Thank you very much for your help!

I tried to use the suggestions to solve the following PDEs and it doesn't seem to work: I try to solve the following system of PDEs:

T = 1; sigma = 1; K = 10; rho = 0.5; gamma = 1; mu = 1; a = 1; sol = NDSolve[{D[p[t,y,s],t] + (a - mu * rho - - (1-rho^2) * sigma^2 * y * D[g[t,y],t])*D[p[t,y,s],y] + 0.5*sigma^2 * D[p[t,y,s],{y,2}] * y + sigma^2 * y * rho * s * D[p[t,y,s],y,s] + 0.5 * sigma^2 * y * s^2* D[p[t,y,s],{s,2}] + 0.5 * sigma^2 * gamma*(1-rho^2)* y * D[p[t,y,s],y]^2 == 0, -D[g[t,y,z],t] + 0.5 * D[g[t,y,z],y]^2*(1-rho^2)*sigma^2*y - 0.5 D[g[t,y],{y,2}]*sigma^2*y - D[g[t,y],y]*a + D[g[t,y],y]*mu*rho - 0.5 (mu^2)/(sigma^2*y) == 0, g[T,y] == 0, p[T,y,s] == Max[s-K,0], p[t,y,0] == 0, p[t,y,100] == 100 - K , (D[p[t,y,s],s] /. s -> 100) == 1 }, {p, g} , {t, 0 , 1}, {y,0.1,10}, {s, 10, 100} , PrecisionGoal -> 10] 
$\endgroup$
2
  • 2
    $\begingroup$ The first is g[x_, y_] = First[f[x, y] /. NDSolve[{D[f[x, y], x, y] == 2*x*y, f[0, y] == 0, f[x, 0] == 0}, f, {x, 0, 10}, {y, 0, 10}]] $\endgroup$ Commented Nov 1, 2017 at 9:21
  • $\begingroup$ Cool, thank you very much! $\endgroup$ Commented Nov 1, 2017 at 10:13

1 Answer 1

1
$\begingroup$

Second question. Since the diffeq for g is second order, you need another condition, so I added one for its x derivative. I also changed g[x] to g[x,y] in your code. This will not make g vary with y, but NDSolve evidently likes all its dependent variables to be consistent. NDSolve can then solve for the two dependent variables f and g. The following works great in M8 (in my opinion the most stable version), but M11 has problems. M11 should be able to do it.

Clear[f, g] sol = NDSolve[{D[f[x, y], x, y] == D[g[x, y], x]*y, D[g[x, y], {x, 2}] == 2, g[0, y] == 0, (D[g[x, y], x] /. x -> 0) == 0, f[0, y] == 0, f[x, 0] == 0}, {f, g}, {x, 0, 10}, {y, 0, 10}]; Plot3D[Evaluate[f[x, y] /. sol[[1]]], {x, 0, 10}, {y, 0, 10}, PlotRange -> All] 

enter image description here

Plot3D[Evaluate[g[x, y] /. sol[[1]]], {x, 0, 10}, {y, 0, 10}, PlotRange -> All] 

enter image description here

You can see that g only varies with x. In fact in this case it is x^2

$\endgroup$
1
  • $\begingroup$ Wow cool. Thank you for your effort and your help. I actually tried to appy this to my actual problem, which is a little bit more complicated and I don't seem to get it working. $\endgroup$ Commented Nov 3, 2017 at 23:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.