Skip to main content
Post Closed as "Duplicate" by Mariusz Iwaniuk, CommunityBot
added 894 characters in body
Source Link
Mariusz Iwaniuk
  • 17.5k
  • 1
  • 29
  • 50

Consider these code, which solve the same equation using DSolve and NDSolve, why do they give different answer? I'm using version 11.0 on WinWindows 8.1.

enter image description here

Another example:

L = 2; eq = D[u[x, t], t] == D[u[x, t], x, x]; opts = Method -> {"MethodOfLines", "SpatialDiscretization" -> {"FiniteElement", "MeshOptions" -> {"MaxCellMeasure" -> 0.001}}}; sol1 = NDSolveValue[{eq, u[x, 0] == x, u[0, t] == 1, u[2, t] == 1}, u, {x, 0, L}, {t, 0, L}, opts]; sol2 = u[x, t] /. First@DSolve[{eq, u[x, 0] == x, u[0, t] == 1, u[2, t] == 1}, u[x, t], {x, t}] (* 1 + Inactive[Sum][-(( 2 (1 + (-1)^K[1]) E^(-(1/4) \[Pi]^2 t K[1]^2) Sin[1/2 \[Pi] x K[1]])/(\[Pi] K[1])), {K[1], 1, \[Infinity]}] *) T = 1/10; Plot[{Evaluate[sol1[x, T]], Evaluate[sol2 /. {Infinity -> 100} /. t -> T // Activate]}, {x, 0, L}, PlotLegends -> {"numeric solution", "symbolic solution"}] 

enter image description here

Consider these code, which solve the same equation using DSolve and NDSolve, why do they give different answer? I'm using version 11.0 on Win.

enter image description here

Consider these code, which solve the same equation using DSolve and NDSolve, why do they give different answer? I'm using version 11.0 on Windows 8.1.

enter image description here

Another example:

L = 2; eq = D[u[x, t], t] == D[u[x, t], x, x]; opts = Method -> {"MethodOfLines", "SpatialDiscretization" -> {"FiniteElement", "MeshOptions" -> {"MaxCellMeasure" -> 0.001}}}; sol1 = NDSolveValue[{eq, u[x, 0] == x, u[0, t] == 1, u[2, t] == 1}, u, {x, 0, L}, {t, 0, L}, opts]; sol2 = u[x, t] /. First@DSolve[{eq, u[x, 0] == x, u[0, t] == 1, u[2, t] == 1}, u[x, t], {x, t}] (* 1 + Inactive[Sum][-(( 2 (1 + (-1)^K[1]) E^(-(1/4) \[Pi]^2 t K[1]^2) Sin[1/2 \[Pi] x K[1]])/(\[Pi] K[1])), {K[1], 1, \[Infinity]}] *) T = 1/10; Plot[{Evaluate[sol1[x, T]], Evaluate[sol2 /. {Infinity -> 100} /. t -> T // Activate]}, {x, 0, L}, PlotLegends -> {"numeric solution", "symbolic solution"}] 

enter image description here

added 165 characters in body
Source Link
Mariusz Iwaniuk
  • 17.5k
  • 1
  • 29
  • 50

Consider these code, which solve the same equation using DSolve and NDSolve, why do they give different answer? I'm using version 11.0 on Win.

eq = D[u[x, t], t] == D[u[x, t], x, x]; icsbc = {u[x, 0] == 1, u[0, t] == 0, u[1, t] == 0}; numer1 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}] numer2 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" -> "FiniteElement"}] numer3 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 200}}] symbol = DSolve[{eq, icsbc}, u[x, t], {x, t}]   

symbol = {{u[x, t] -> Inactive[Sum][-(( 2 (-1 + (-1)^K[1]) E^(-\[Pi]^2 t K[1]^2) Sin[\[Pi] x K[1]])/(\[Pi] K[1])), {K[1], 1, \[Infinity]}]}}

Plot[{Evaluate[u[x, 1/2] /. numer1], Evaluate[u[x, 1/2] /. numer2], Evaluate[u[x, 1/2] /. numer3], Evaluate[(u[x, t] /. symbol[[1]] /. t -> 1/2 /. {Infinity -> 10} // Activate)]}, {x, 0, 1}, PlotLegends -> {"numeric1", "numeric2", "numeric3", "symbolic"}, PlotStyle -> {{Green, Dashing[{0.1, 0.1}], Thin}, {Blue, Dashing[{0.05, 0.05}], Thin}, {Yellow, Dashing[{0.01, 0.01}], Thin}, {Black, Thickness[0.02]}}] 

enter image description here

Consider these code, which solve the same equation using DSolve and NDSolve, why do they give different answer? I'm using version 11.0 on Win.

eq = D[u[x, t], t] == D[u[x, t], x, x]; icsbc = {u[x, 0] == 1, u[0, t] == 0, u[1, t] == 0}; numer1 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}] numer2 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" -> "FiniteElement"}] numer3 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 200}}] symbol = DSolve[{eq, icsbc}, u[x, t], {x, t}]   Plot[{Evaluate[u[x, 1/2] /. numer1], Evaluate[u[x, 1/2] /. numer2], Evaluate[u[x, 1/2] /. numer3], Evaluate[(u[x, t] /. symbol[[1]] /. t -> 1/2 /. {Infinity -> 10} // Activate)]}, {x, 0, 1}, PlotLegends -> {"numeric1", "numeric2", "numeric3", "symbolic"}, PlotStyle -> {{Green, Dashing[{0.1, 0.1}], Thin}, {Blue, Dashing[{0.05, 0.05}], Thin}, {Yellow, Dashing[{0.01, 0.01}], Thin}, {Black, Thickness[0.02]}}] 

enter image description here

Consider these code, which solve the same equation using DSolve and NDSolve, why do they give different answer? I'm using version 11.0 on Win.

eq = D[u[x, t], t] == D[u[x, t], x, x]; icsbc = {u[x, 0] == 1, u[0, t] == 0, u[1, t] == 0}; numer1 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}] numer2 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" -> "FiniteElement"}] numer3 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 200}}] symbol = DSolve[{eq, icsbc}, u[x, t], {x, t}] 

symbol = {{u[x, t] -> Inactive[Sum][-(( 2 (-1 + (-1)^K[1]) E^(-\[Pi]^2 t K[1]^2) Sin[\[Pi] x K[1]])/(\[Pi] K[1])), {K[1], 1, \[Infinity]}]}}

Plot[{Evaluate[u[x, 1/2] /. numer1], Evaluate[u[x, 1/2] /. numer2], Evaluate[u[x, 1/2] /. numer3], Evaluate[(u[x, t] /. symbol[[1]] /. t -> 1/2 /. {Infinity -> 10} // Activate)]}, {x, 0, 1}, PlotLegends -> {"numeric1", "numeric2", "numeric3", "symbolic"}, PlotStyle -> {{Green, Dashing[{0.1, 0.1}], Thin}, {Blue, Dashing[{0.05, 0.05}], Thin}, {Yellow, Dashing[{0.01, 0.01}], Thin}, {Black, Thickness[0.02]}}] 

enter image description here

Source Link
Mariusz Iwaniuk
  • 17.5k
  • 1
  • 29
  • 50

Why DSolve and NDSolve give different answer?

Consider these code, which solve the same equation using DSolve and NDSolve, why do they give different answer? I'm using version 11.0 on Win.

eq = D[u[x, t], t] == D[u[x, t], x, x]; icsbc = {u[x, 0] == 1, u[0, t] == 0, u[1, t] == 0}; numer1 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}] numer2 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" -> "FiniteElement"}] numer3 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 200}}] symbol = DSolve[{eq, icsbc}, u[x, t], {x, t}] Plot[{Evaluate[u[x, 1/2] /. numer1], Evaluate[u[x, 1/2] /. numer2], Evaluate[u[x, 1/2] /. numer3], Evaluate[(u[x, t] /. symbol[[1]] /. t -> 1/2 /. {Infinity -> 10} // Activate)]}, {x, 0, 1}, PlotLegends -> {"numeric1", "numeric2", "numeric3", "symbolic"}, PlotStyle -> {{Green, Dashing[{0.1, 0.1}], Thin}, {Blue, Dashing[{0.05, 0.05}], Thin}, {Yellow, Dashing[{0.01, 0.01}], Thin}, {Black, Thickness[0.02]}}] 

enter image description here