0

I'm solving the 1D Poisson equation and am getting some funky numerical artifacts in the solution.

ClearAll["Global`*"];

L = 10.0;

alpha = 2.0*Pi/L;

f[x_] := (alpha^2)*Sin[alpha*x];

sol = DSolve[{-v''[x] == f[x], v[L] == 0, v[0] == 0}, v[x], {x, 0, L}];

v[x_] = v[x] /. sol

{2.44929*10^-17 x + 1. Sin[0.628319 x]}

The analytic solution really should be Sin[0.628319 x]. Why am I getting a small coefficient in front of the x in the first term. I thought DSolve was strictly symbolic.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257

1 Answers1

3

As Michel E2 said in his comment, DSolve is not and not be symbolic if you give it expressions containing inexact quantities. So try

Clear @ v
L = 10;
alpha = 2*Pi/L;
f[x_] := (alpha^2)*Sin[alpha*x];
sol = DSolve[{-v''[x] == f[x], v[L] == 0, v[0] == 0}, v[x], x];
v[x_] = N[v[x] /. sol[[1]]]
Sin[0.628319 x]
m_goldberg
  • 107,779
  • 16
  • 103
  • 257