# NDSolve gives crappy results?

Posted 8 years ago
5945 Views
|
|
0 Total Likes
|
 I have been trying out mathematica 10 features, but sadly unable to use NDSolve for even simple PDE's. I am still wrestling with the problem of boundary conditions. The solution I get in the interpolating function doesn't have proper values specified in the boundary conditions. For example if I specify DirichletCondition[V[S, t] == 10.0, (S >= 110 && t == 1.0)] And if i check the boundary condition V[110,1.0] it doesn't give 10.0 as the result. The values don't make sense.Here's my original problem  soln = NDSolveValue[ {D[V[S, t], t] + r*S*D[V[S, t], S] + 0.5 sigma^2 S^2 D[V[S,t], {S,2}] - r V[S,t] == 0, DirichletCondition[V[S, t] == 20.0, (S >= 110 && t == 2.0)], DirichletCondition[V[S, t] == 10.0, (S >= 110 && t == 1.0)], DirichletCondition[V[S, t] == -Max[80 - S, 0], (S <= 80 && t == 2.0)], DirichletCondition[V[S, t] == 0.0, (S > 80 && S < 110 && t == 2.0)]}, V, {S, t} ? mesh]; autocall[130, 1.0] (* 15.3241 *) which doesn't make any sense!The condition stated preciely that at t = 1.0 make the value 10.0 for S greater than or equal to 110.0.I am using the following mesh ? = ImplicitRegion[True, {{S, 0, 200}, {t, 0, 2.0}}]; mesh = ToElementMesh[?, MaxCellMeasure -> 0.005 , "MeshOrder" -> 2]; Strangest part is mathematica doesn't give any errors and now I think problem is with the interpolating function which is not satisfying the boundary conditions. After I remove the inner condition, DirichletCondition[V[S, t] == 10.0, (S >= 110 && t == 1.0)], I don't observe any change in price. Probably it's not even hitting this boundary. Probably I need to generate a mesh with exact boundries of t == 1.0. For t==2.0 it already works coz it's the extreme end. Maybe mathematica is not able to figure out that at t == 1.0, the value jumps to 10.0. As of now I can only forsee two solutions Figure out how to create a mesh with explicit boundaries Give up on NDSolve coz it's not meant for above cases! -- I don't think this is possible ;) What I am doing wrong, any suggestions? Any clues on how to solve this simple PDE? Have given up partially on this tool after trying various other options...maybe NDSolveValue is not built for such problems. Attachments:
 Found the solution, actually it was my mistake not to specify boundary points mesh = ToBoundaryMesh["Coordinates" -> {{0, 0}, {200, 0}, {200, 1}, {110, 1}, {200, 2}, {0, 2}, {80, 2}}, "BoundaryElements" ->{LineElement[{{1, 2}, {2, 3}, {3, 4}, {3, 5}, {5, 6}, {6, 1}, {6, 7}}]}] mesh2 := ToElementMesh[mesh, MaxCellMeasure -> 0.01] If I use the above mesh2 for solving the PDE, it gives perfect solution. I didn't know how to use LineElement at first, coz the indexing is a bit wierd and the documentation was not clear. But i guess this method is very simple to use once you get it! Hope this helps someone trying to use NDSolve for boundary value problems. Attachments: