0
|
4703 Views
|
|
1 Total Likes
View groups...
Share
GROUPS:

# Mathematica Plotting Issue

Posted 8 years ago
 I'm using Mathematica to solve an initial value problem, and then plot it. However, When I try and plot it I'm receiving an error message. The problem I'm trying to graph is Here is my code: \[Kappa] = 1/4; L = 4; f[x_] = Piecewise[{{100*Sin[Pi*x], 0 <= x < 2}, {0, 2 <= x < 4}}] Plot[f[x], {x, 0, 4}, AxesLabel -> Automatic, PlotRange -> Full] un[x_, t_, n_] = Exp[-1/4*(n Pi/4)^2 t] Sin[n Pi x/4] an[n_] = 2/4 Integrate[f[x]*Sin[n Pi x/4], {x, 0, 4}] an[n_] = Simplify[an[n], n \[Element] Integers] u[x_, t_, m_] = Sum[an[n] un[x, t, n], {n, 1, m}] Plot[{f[x], u[x, 0, 1]}, {x, 0, L}, AxesLabel -> Automatic, PlotLegends -> "Expressions"] Plot[{f[x], u[x, 0, 20]}, {x, 0, L}, AxesLabel -> Automatic, PlotLegends -> "Expressions"]  The last part of my code, where I am trying to change the value of m is where I running into issues. How can I fix this? Thanks!
 Have you tried with a delayed definition u[x_, t_, m_] := Sum[an[n] un[x, t, n], {n, 1, m}] ? Mathematica may have trouble finding a closed form for the symbolic sum. With the delayed definition the sum in evaluated when the parameters are numeric, which is easier.