Euler's method initial value problem — how should I plot the solution?
$begingroup$
We are given the following initial value problem:
$qquad y' = t,e^{3,t} -2,y, quad 0 le t le 1, quad y(0)=0$
Use Euler`s method to approximate the solution to this initial value problem. In this case, the step size is $h=0.5$.
Plot the approximating solution $y_k$ along with the exact solution $y(t)$.
plotting differential-equations homework
$endgroup$
add a comment |
$begingroup$
We are given the following initial value problem:
$qquad y' = t,e^{3,t} -2,y, quad 0 le t le 1, quad y(0)=0$
Use Euler`s method to approximate the solution to this initial value problem. In this case, the step size is $h=0.5$.
Plot the approximating solution $y_k$ along with the exact solution $y(t)$.
plotting differential-equations homework
$endgroup$
$begingroup$
Are you sure that you are in the right forum? This one is about the Mathematica software. Perhaps this might fit better in math.stackexchange.com?
$endgroup$
– MarcoB
Mar 24 at 1:36
$begingroup$
Yes, plot the calculated $y$ vs $t$ at the computed points. Below is an example computed in Mathematica. $n=20$ steps.
$endgroup$
– mjw
Mar 24 at 2:18
2
$begingroup$
A related question.
$endgroup$
– J. M. is slightly pensive♦
Mar 24 at 2:41
$begingroup$
@J.M., Yes, your method there (at the linked question) is a nice way to go about it!
$endgroup$
– mjw
Mar 24 at 5:27
add a comment |
$begingroup$
We are given the following initial value problem:
$qquad y' = t,e^{3,t} -2,y, quad 0 le t le 1, quad y(0)=0$
Use Euler`s method to approximate the solution to this initial value problem. In this case, the step size is $h=0.5$.
Plot the approximating solution $y_k$ along with the exact solution $y(t)$.
plotting differential-equations homework
$endgroup$
We are given the following initial value problem:
$qquad y' = t,e^{3,t} -2,y, quad 0 le t le 1, quad y(0)=0$
Use Euler`s method to approximate the solution to this initial value problem. In this case, the step size is $h=0.5$.
Plot the approximating solution $y_k$ along with the exact solution $y(t)$.
plotting differential-equations homework
plotting differential-equations homework
edited Mar 28 at 16:51
mjw
1,24810
1,24810
asked Mar 24 at 0:38
KevinKevin
111
111
$begingroup$
Are you sure that you are in the right forum? This one is about the Mathematica software. Perhaps this might fit better in math.stackexchange.com?
$endgroup$
– MarcoB
Mar 24 at 1:36
$begingroup$
Yes, plot the calculated $y$ vs $t$ at the computed points. Below is an example computed in Mathematica. $n=20$ steps.
$endgroup$
– mjw
Mar 24 at 2:18
2
$begingroup$
A related question.
$endgroup$
– J. M. is slightly pensive♦
Mar 24 at 2:41
$begingroup$
@J.M., Yes, your method there (at the linked question) is a nice way to go about it!
$endgroup$
– mjw
Mar 24 at 5:27
add a comment |
$begingroup$
Are you sure that you are in the right forum? This one is about the Mathematica software. Perhaps this might fit better in math.stackexchange.com?
$endgroup$
– MarcoB
Mar 24 at 1:36
$begingroup$
Yes, plot the calculated $y$ vs $t$ at the computed points. Below is an example computed in Mathematica. $n=20$ steps.
$endgroup$
– mjw
Mar 24 at 2:18
2
$begingroup$
A related question.
$endgroup$
– J. M. is slightly pensive♦
Mar 24 at 2:41
$begingroup$
@J.M., Yes, your method there (at the linked question) is a nice way to go about it!
$endgroup$
– mjw
Mar 24 at 5:27
$begingroup$
Are you sure that you are in the right forum? This one is about the Mathematica software. Perhaps this might fit better in math.stackexchange.com?
$endgroup$
– MarcoB
Mar 24 at 1:36
$begingroup$
Are you sure that you are in the right forum? This one is about the Mathematica software. Perhaps this might fit better in math.stackexchange.com?
$endgroup$
– MarcoB
Mar 24 at 1:36
$begingroup$
Yes, plot the calculated $y$ vs $t$ at the computed points. Below is an example computed in Mathematica. $n=20$ steps.
$endgroup$
– mjw
Mar 24 at 2:18
$begingroup$
Yes, plot the calculated $y$ vs $t$ at the computed points. Below is an example computed in Mathematica. $n=20$ steps.
$endgroup$
– mjw
Mar 24 at 2:18
2
2
$begingroup$
A related question.
$endgroup$
– J. M. is slightly pensive♦
Mar 24 at 2:41
$begingroup$
A related question.
$endgroup$
– J. M. is slightly pensive♦
Mar 24 at 2:41
$begingroup$
@J.M., Yes, your method there (at the linked question) is a nice way to go about it!
$endgroup$
– mjw
Mar 24 at 5:27
$begingroup$
@J.M., Yes, your method there (at the linked question) is a nice way to go about it!
$endgroup$
– mjw
Mar 24 at 5:27
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
Euler's method to solve, plot, and compare to known solution:
$y^prime = te^{3t}-2y, quad y(0)=0, quad 0 le t le 1. $
y = 0; t = 0.0;
n = 20; h = 1/n;
f[y_, t_] := t Exp[3 t] - 2 y;
ξ = {y};
Do[(
y = y + f[y, t] h;
t = t + h;
ξ = Join[ξ, {y}]
), n
]
p = Transpose[{Range[0, n]/n, ξ}];
Clear[y, t];
DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t]
q = Plot[Evaluate[y[t] /. %], {t, 0, 1}, PlotStyle -> Gray];
Show[q, ListPlot[p, PlotStyle -> Blue]]
Here is the output from DSolve
:
{{y[t] -> 1/25 E^(-2 t) (1 - E^(5 t) + 5 E^(5 t) t)}}
Or in plain English, the solution is:
$y(t) = frac{1}{25} (e^{-2 t} - e^{3t}+5t e^{3t})$
Here is the plot of the computed points along with the known solution (computed with DSolve
above).
With $h=0.5$, Euler's method does not do so well:
Again, for $h=1/20$, we can compute y[t]
at each approximation point and store it in the list $eta$:
m = DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t];
[Eta] = y[t] /. m /. t -> Range[0.0, n]/n;
Then we can tabulated $t, xi, eta$ (The list $xi$ contains the Euler approximations).
TableForm[Transpose@Join[Transpose@N@p, [Eta]]]
$begin{array}{lll}
0.00 &0.00000000 &0.00000000\
0.05 &0.00000000 &0.00133847\
0.10 &0.00290459 &0.00575205\
0.15 &0.00936342 &0.01394960\
0.20 &0.02018940 &0.02681280\
0.25 &0.03639170 &0.04543120\
0.30 &0.05921500 &0.07114450\
0.35 &0.09018750 &0.10559300\
0.40 &0.13117800 &0.15077800\
0.45 &0.18446200 &0.20913400\
0.50 &0.25280800 &0.28361700\
0.55 &0.33957000 &0.37780300\
0.60 &0.44880500 &0.49602000\
0.65 &0.58541300 &0.64348300\
0.70 &0.75530400 &0.82648100\
0.75 &0.96559000 &1.05258000\
0.80 &1.22482000 &1.33086000\
0.85 &1.54327000 &1.67223000\
0.90 &1.93324000 &2.08977000\
0.95 &2.40951000 &2.59915000\
1.00 &2.98972000 &3.21910000\
end{array}$
We can also plot the error $ = eta - xi$:
ListPlot[Transpose@{Range[0, n]/n, Flatten@[Eta] - [Xi]},
Axes -> False, Frame -> True,
FrameLabel -> {t, "Error=y[t]-Euler Approx."}]
$endgroup$
add a comment |
$begingroup$
forwardEuler[{t_, y_}] := {t + h, y + h f[t, y]} // N
f[t_, y_] = t*Exp[3 t] - 2 y;
h = 0.5;
steps = Floor[(1 - 0)/h]; (*0 <= t <=1 *)
ics = {0, 0};
With h=0.5 you get only 3 points,
NestList[forwardEuler, ics, steps]
{{0, 0}, {0.5, 0.}, {1., 1.12042}}
You have to choose more steps!
h = 0.05;
steps = Floor[(1 - 0)/h];
euler = NestList[forwardEuler, ics, steps];
ListLinePlot[euler, GridLines -> Automatic]
$endgroup$
$begingroup$
Looking at your solution, I realized that I updated $t_{n+1} = t_n +h$ too early. I've made the correction in my answer. Thank you very much!
$endgroup$
– mjw
Mar 24 at 13:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f193856%2feulers-method-initial-value-problem-how-should-i-plot-the-solution%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Euler's method to solve, plot, and compare to known solution:
$y^prime = te^{3t}-2y, quad y(0)=0, quad 0 le t le 1. $
y = 0; t = 0.0;
n = 20; h = 1/n;
f[y_, t_] := t Exp[3 t] - 2 y;
ξ = {y};
Do[(
y = y + f[y, t] h;
t = t + h;
ξ = Join[ξ, {y}]
), n
]
p = Transpose[{Range[0, n]/n, ξ}];
Clear[y, t];
DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t]
q = Plot[Evaluate[y[t] /. %], {t, 0, 1}, PlotStyle -> Gray];
Show[q, ListPlot[p, PlotStyle -> Blue]]
Here is the output from DSolve
:
{{y[t] -> 1/25 E^(-2 t) (1 - E^(5 t) + 5 E^(5 t) t)}}
Or in plain English, the solution is:
$y(t) = frac{1}{25} (e^{-2 t} - e^{3t}+5t e^{3t})$
Here is the plot of the computed points along with the known solution (computed with DSolve
above).
With $h=0.5$, Euler's method does not do so well:
Again, for $h=1/20$, we can compute y[t]
at each approximation point and store it in the list $eta$:
m = DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t];
[Eta] = y[t] /. m /. t -> Range[0.0, n]/n;
Then we can tabulated $t, xi, eta$ (The list $xi$ contains the Euler approximations).
TableForm[Transpose@Join[Transpose@N@p, [Eta]]]
$begin{array}{lll}
0.00 &0.00000000 &0.00000000\
0.05 &0.00000000 &0.00133847\
0.10 &0.00290459 &0.00575205\
0.15 &0.00936342 &0.01394960\
0.20 &0.02018940 &0.02681280\
0.25 &0.03639170 &0.04543120\
0.30 &0.05921500 &0.07114450\
0.35 &0.09018750 &0.10559300\
0.40 &0.13117800 &0.15077800\
0.45 &0.18446200 &0.20913400\
0.50 &0.25280800 &0.28361700\
0.55 &0.33957000 &0.37780300\
0.60 &0.44880500 &0.49602000\
0.65 &0.58541300 &0.64348300\
0.70 &0.75530400 &0.82648100\
0.75 &0.96559000 &1.05258000\
0.80 &1.22482000 &1.33086000\
0.85 &1.54327000 &1.67223000\
0.90 &1.93324000 &2.08977000\
0.95 &2.40951000 &2.59915000\
1.00 &2.98972000 &3.21910000\
end{array}$
We can also plot the error $ = eta - xi$:
ListPlot[Transpose@{Range[0, n]/n, Flatten@[Eta] - [Xi]},
Axes -> False, Frame -> True,
FrameLabel -> {t, "Error=y[t]-Euler Approx."}]
$endgroup$
add a comment |
$begingroup$
Euler's method to solve, plot, and compare to known solution:
$y^prime = te^{3t}-2y, quad y(0)=0, quad 0 le t le 1. $
y = 0; t = 0.0;
n = 20; h = 1/n;
f[y_, t_] := t Exp[3 t] - 2 y;
ξ = {y};
Do[(
y = y + f[y, t] h;
t = t + h;
ξ = Join[ξ, {y}]
), n
]
p = Transpose[{Range[0, n]/n, ξ}];
Clear[y, t];
DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t]
q = Plot[Evaluate[y[t] /. %], {t, 0, 1}, PlotStyle -> Gray];
Show[q, ListPlot[p, PlotStyle -> Blue]]
Here is the output from DSolve
:
{{y[t] -> 1/25 E^(-2 t) (1 - E^(5 t) + 5 E^(5 t) t)}}
Or in plain English, the solution is:
$y(t) = frac{1}{25} (e^{-2 t} - e^{3t}+5t e^{3t})$
Here is the plot of the computed points along with the known solution (computed with DSolve
above).
With $h=0.5$, Euler's method does not do so well:
Again, for $h=1/20$, we can compute y[t]
at each approximation point and store it in the list $eta$:
m = DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t];
[Eta] = y[t] /. m /. t -> Range[0.0, n]/n;
Then we can tabulated $t, xi, eta$ (The list $xi$ contains the Euler approximations).
TableForm[Transpose@Join[Transpose@N@p, [Eta]]]
$begin{array}{lll}
0.00 &0.00000000 &0.00000000\
0.05 &0.00000000 &0.00133847\
0.10 &0.00290459 &0.00575205\
0.15 &0.00936342 &0.01394960\
0.20 &0.02018940 &0.02681280\
0.25 &0.03639170 &0.04543120\
0.30 &0.05921500 &0.07114450\
0.35 &0.09018750 &0.10559300\
0.40 &0.13117800 &0.15077800\
0.45 &0.18446200 &0.20913400\
0.50 &0.25280800 &0.28361700\
0.55 &0.33957000 &0.37780300\
0.60 &0.44880500 &0.49602000\
0.65 &0.58541300 &0.64348300\
0.70 &0.75530400 &0.82648100\
0.75 &0.96559000 &1.05258000\
0.80 &1.22482000 &1.33086000\
0.85 &1.54327000 &1.67223000\
0.90 &1.93324000 &2.08977000\
0.95 &2.40951000 &2.59915000\
1.00 &2.98972000 &3.21910000\
end{array}$
We can also plot the error $ = eta - xi$:
ListPlot[Transpose@{Range[0, n]/n, Flatten@[Eta] - [Xi]},
Axes -> False, Frame -> True,
FrameLabel -> {t, "Error=y[t]-Euler Approx."}]
$endgroup$
add a comment |
$begingroup$
Euler's method to solve, plot, and compare to known solution:
$y^prime = te^{3t}-2y, quad y(0)=0, quad 0 le t le 1. $
y = 0; t = 0.0;
n = 20; h = 1/n;
f[y_, t_] := t Exp[3 t] - 2 y;
ξ = {y};
Do[(
y = y + f[y, t] h;
t = t + h;
ξ = Join[ξ, {y}]
), n
]
p = Transpose[{Range[0, n]/n, ξ}];
Clear[y, t];
DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t]
q = Plot[Evaluate[y[t] /. %], {t, 0, 1}, PlotStyle -> Gray];
Show[q, ListPlot[p, PlotStyle -> Blue]]
Here is the output from DSolve
:
{{y[t] -> 1/25 E^(-2 t) (1 - E^(5 t) + 5 E^(5 t) t)}}
Or in plain English, the solution is:
$y(t) = frac{1}{25} (e^{-2 t} - e^{3t}+5t e^{3t})$
Here is the plot of the computed points along with the known solution (computed with DSolve
above).
With $h=0.5$, Euler's method does not do so well:
Again, for $h=1/20$, we can compute y[t]
at each approximation point and store it in the list $eta$:
m = DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t];
[Eta] = y[t] /. m /. t -> Range[0.0, n]/n;
Then we can tabulated $t, xi, eta$ (The list $xi$ contains the Euler approximations).
TableForm[Transpose@Join[Transpose@N@p, [Eta]]]
$begin{array}{lll}
0.00 &0.00000000 &0.00000000\
0.05 &0.00000000 &0.00133847\
0.10 &0.00290459 &0.00575205\
0.15 &0.00936342 &0.01394960\
0.20 &0.02018940 &0.02681280\
0.25 &0.03639170 &0.04543120\
0.30 &0.05921500 &0.07114450\
0.35 &0.09018750 &0.10559300\
0.40 &0.13117800 &0.15077800\
0.45 &0.18446200 &0.20913400\
0.50 &0.25280800 &0.28361700\
0.55 &0.33957000 &0.37780300\
0.60 &0.44880500 &0.49602000\
0.65 &0.58541300 &0.64348300\
0.70 &0.75530400 &0.82648100\
0.75 &0.96559000 &1.05258000\
0.80 &1.22482000 &1.33086000\
0.85 &1.54327000 &1.67223000\
0.90 &1.93324000 &2.08977000\
0.95 &2.40951000 &2.59915000\
1.00 &2.98972000 &3.21910000\
end{array}$
We can also plot the error $ = eta - xi$:
ListPlot[Transpose@{Range[0, n]/n, Flatten@[Eta] - [Xi]},
Axes -> False, Frame -> True,
FrameLabel -> {t, "Error=y[t]-Euler Approx."}]
$endgroup$
Euler's method to solve, plot, and compare to known solution:
$y^prime = te^{3t}-2y, quad y(0)=0, quad 0 le t le 1. $
y = 0; t = 0.0;
n = 20; h = 1/n;
f[y_, t_] := t Exp[3 t] - 2 y;
ξ = {y};
Do[(
y = y + f[y, t] h;
t = t + h;
ξ = Join[ξ, {y}]
), n
]
p = Transpose[{Range[0, n]/n, ξ}];
Clear[y, t];
DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t]
q = Plot[Evaluate[y[t] /. %], {t, 0, 1}, PlotStyle -> Gray];
Show[q, ListPlot[p, PlotStyle -> Blue]]
Here is the output from DSolve
:
{{y[t] -> 1/25 E^(-2 t) (1 - E^(5 t) + 5 E^(5 t) t)}}
Or in plain English, the solution is:
$y(t) = frac{1}{25} (e^{-2 t} - e^{3t}+5t e^{3t})$
Here is the plot of the computed points along with the known solution (computed with DSolve
above).
With $h=0.5$, Euler's method does not do so well:
Again, for $h=1/20$, we can compute y[t]
at each approximation point and store it in the list $eta$:
m = DSolve[{y'[t] == t Exp[3 t] - 2 y[t], y[0] == 0}, y[t], t];
[Eta] = y[t] /. m /. t -> Range[0.0, n]/n;
Then we can tabulated $t, xi, eta$ (The list $xi$ contains the Euler approximations).
TableForm[Transpose@Join[Transpose@N@p, [Eta]]]
$begin{array}{lll}
0.00 &0.00000000 &0.00000000\
0.05 &0.00000000 &0.00133847\
0.10 &0.00290459 &0.00575205\
0.15 &0.00936342 &0.01394960\
0.20 &0.02018940 &0.02681280\
0.25 &0.03639170 &0.04543120\
0.30 &0.05921500 &0.07114450\
0.35 &0.09018750 &0.10559300\
0.40 &0.13117800 &0.15077800\
0.45 &0.18446200 &0.20913400\
0.50 &0.25280800 &0.28361700\
0.55 &0.33957000 &0.37780300\
0.60 &0.44880500 &0.49602000\
0.65 &0.58541300 &0.64348300\
0.70 &0.75530400 &0.82648100\
0.75 &0.96559000 &1.05258000\
0.80 &1.22482000 &1.33086000\
0.85 &1.54327000 &1.67223000\
0.90 &1.93324000 &2.08977000\
0.95 &2.40951000 &2.59915000\
1.00 &2.98972000 &3.21910000\
end{array}$
We can also plot the error $ = eta - xi$:
ListPlot[Transpose@{Range[0, n]/n, Flatten@[Eta] - [Xi]},
Axes -> False, Frame -> True,
FrameLabel -> {t, "Error=y[t]-Euler Approx."}]
edited Mar 24 at 19:21
answered Mar 24 at 2:17
mjwmjw
1,24810
1,24810
add a comment |
add a comment |
$begingroup$
forwardEuler[{t_, y_}] := {t + h, y + h f[t, y]} // N
f[t_, y_] = t*Exp[3 t] - 2 y;
h = 0.5;
steps = Floor[(1 - 0)/h]; (*0 <= t <=1 *)
ics = {0, 0};
With h=0.5 you get only 3 points,
NestList[forwardEuler, ics, steps]
{{0, 0}, {0.5, 0.}, {1., 1.12042}}
You have to choose more steps!
h = 0.05;
steps = Floor[(1 - 0)/h];
euler = NestList[forwardEuler, ics, steps];
ListLinePlot[euler, GridLines -> Automatic]
$endgroup$
$begingroup$
Looking at your solution, I realized that I updated $t_{n+1} = t_n +h$ too early. I've made the correction in my answer. Thank you very much!
$endgroup$
– mjw
Mar 24 at 13:40
add a comment |
$begingroup$
forwardEuler[{t_, y_}] := {t + h, y + h f[t, y]} // N
f[t_, y_] = t*Exp[3 t] - 2 y;
h = 0.5;
steps = Floor[(1 - 0)/h]; (*0 <= t <=1 *)
ics = {0, 0};
With h=0.5 you get only 3 points,
NestList[forwardEuler, ics, steps]
{{0, 0}, {0.5, 0.}, {1., 1.12042}}
You have to choose more steps!
h = 0.05;
steps = Floor[(1 - 0)/h];
euler = NestList[forwardEuler, ics, steps];
ListLinePlot[euler, GridLines -> Automatic]
$endgroup$
$begingroup$
Looking at your solution, I realized that I updated $t_{n+1} = t_n +h$ too early. I've made the correction in my answer. Thank you very much!
$endgroup$
– mjw
Mar 24 at 13:40
add a comment |
$begingroup$
forwardEuler[{t_, y_}] := {t + h, y + h f[t, y]} // N
f[t_, y_] = t*Exp[3 t] - 2 y;
h = 0.5;
steps = Floor[(1 - 0)/h]; (*0 <= t <=1 *)
ics = {0, 0};
With h=0.5 you get only 3 points,
NestList[forwardEuler, ics, steps]
{{0, 0}, {0.5, 0.}, {1., 1.12042}}
You have to choose more steps!
h = 0.05;
steps = Floor[(1 - 0)/h];
euler = NestList[forwardEuler, ics, steps];
ListLinePlot[euler, GridLines -> Automatic]
$endgroup$
forwardEuler[{t_, y_}] := {t + h, y + h f[t, y]} // N
f[t_, y_] = t*Exp[3 t] - 2 y;
h = 0.5;
steps = Floor[(1 - 0)/h]; (*0 <= t <=1 *)
ics = {0, 0};
With h=0.5 you get only 3 points,
NestList[forwardEuler, ics, steps]
{{0, 0}, {0.5, 0.}, {1., 1.12042}}
You have to choose more steps!
h = 0.05;
steps = Floor[(1 - 0)/h];
euler = NestList[forwardEuler, ics, steps];
ListLinePlot[euler, GridLines -> Automatic]
answered Mar 24 at 11:40
rmwrmw
39817
39817
$begingroup$
Looking at your solution, I realized that I updated $t_{n+1} = t_n +h$ too early. I've made the correction in my answer. Thank you very much!
$endgroup$
– mjw
Mar 24 at 13:40
add a comment |
$begingroup$
Looking at your solution, I realized that I updated $t_{n+1} = t_n +h$ too early. I've made the correction in my answer. Thank you very much!
$endgroup$
– mjw
Mar 24 at 13:40
$begingroup$
Looking at your solution, I realized that I updated $t_{n+1} = t_n +h$ too early. I've made the correction in my answer. Thank you very much!
$endgroup$
– mjw
Mar 24 at 13:40
$begingroup$
Looking at your solution, I realized that I updated $t_{n+1} = t_n +h$ too early. I've made the correction in my answer. Thank you very much!
$endgroup$
– mjw
Mar 24 at 13:40
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f193856%2feulers-method-initial-value-problem-how-should-i-plot-the-solution%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Are you sure that you are in the right forum? This one is about the Mathematica software. Perhaps this might fit better in math.stackexchange.com?
$endgroup$
– MarcoB
Mar 24 at 1:36
$begingroup$
Yes, plot the calculated $y$ vs $t$ at the computed points. Below is an example computed in Mathematica. $n=20$ steps.
$endgroup$
– mjw
Mar 24 at 2:18
2
$begingroup$
A related question.
$endgroup$
– J. M. is slightly pensive♦
Mar 24 at 2:41
$begingroup$
@J.M., Yes, your method there (at the linked question) is a nice way to go about it!
$endgroup$
– mjw
Mar 24 at 5:27