Skip to content

Commit e11b51c

Browse files
committed
updated versions
1 parent c619dca commit e11b51c

File tree

267 files changed

+5719
-7098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

267 files changed

+5719
-7098
lines changed

docs/RK1_euler_doc.html

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
2+
<!DOCTYPE html
3+
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4+
<html><head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<!--
7+
This HTML was auto-generated from MATLAB code.
8+
To make changes, update the MATLAB code and republish this document.
9+
--><title>RK1_euler</title><meta name="generator" content="MATLAB 9.11"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2022-06-04"><meta name="DC.source" content="RK1_euler_doc.m"><style type="text/css">
10+
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
11+
12+
html { min-height:100%; margin-bottom:1px; }
13+
html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; }
14+
html body td { vertical-align:top; text-align:left; }
15+
16+
h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; }
17+
h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; }
18+
h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; }
19+
20+
a { color:#005fce; text-decoration:none; }
21+
a:hover { color:#005fce; text-decoration:underline; }
22+
a:visited { color:#004aa0; text-decoration:none; }
23+
24+
p { padding:0px; margin:0px 0px 20px; }
25+
img { padding:0px; margin:0px 0px 20px; border:none; }
26+
p img, pre img, tt img, li img, h1 img, h2 img { margin-bottom:0px; }
27+
28+
ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; }
29+
ul li { padding:0px; margin:0px 0px 7px 0px; }
30+
ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; }
31+
ul li ol li { list-style:decimal; }
32+
ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; }
33+
ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; }
34+
ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; }
35+
ol li ol li { list-style-type:lower-alpha; }
36+
ol li ul { padding-top:7px; }
37+
ol li ul li { list-style:square; }
38+
39+
.content { font-size:1.2em; line-height:140%; padding: 20px; }
40+
41+
pre, code { font-size:12px; }
42+
tt { font-size: 1.2em; }
43+
pre { margin:0px 0px 20px; }
44+
pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; }
45+
pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; }
46+
pre.error { color:red; }
47+
48+
@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } }
49+
50+
span.keyword { color:#0000FF }
51+
span.comment { color:#228B22 }
52+
span.string { color:#A020F0 }
53+
span.untermstring { color:#B20000 }
54+
span.syscmd { color:#B28C00 }
55+
span.typesection { color:#A0522D }
56+
57+
.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; }
58+
.footer p { margin:0px; }
59+
.footer a { color:#878787; }
60+
.footer a:hover { color:#878787; text-decoration:underline; }
61+
.footer a:visited { color:#878787; }
62+
63+
table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; }
64+
table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; }
65+
66+
67+
68+
69+
70+
</style></head><body><div class="content"><h1><tt>RK1_euler</tt></h1><!--introduction--><p>Propagates the state vector forward one time step using the Euler (first-order) method.</p><p><a href="index.html">Back to ODE Solver Toolbox Contents</a>.</p><!--/introduction--><h2>Contents</h2><div><ul><li><a href="#1">Syntax</a></li><li><a href="#2">Description</a></li><li><a href="#3">Input/Output Parameters</a></li><li><a href="#4">Example</a></li><li><a href="#8">See also</a></li></ul></div><h2 id="1">Syntax</h2><pre class="language-matlab">y_next = RK1_euler(f,t,y,h)
71+
</pre><h2 id="2">Description</h2><p><tt>y_next = RK1_euler(f,t,y,h)</tt> returns the state vector at the next sample time, <tt>y_next</tt>, given the current state vector <tt>y</tt> at time <tt>t</tt>, the function <tt>f(t,y)</tt> defining the ODE <img src="RK1_euler_doc_eq13964145860186194730.png" alt="$\dot{\mathbf{y}}=\mathbf{f}(t,\mathbf{y})$" style="width:50px;height:11px;">, and the step size <tt>h</tt>.</p><h2 id="3">Input/Output Parameters</h2><p>
72+
<table border=1>
73+
<tr>
74+
<td></td>
75+
<td style="text-align:center"><b>Variable</b></td>
76+
<td style="text-align:center"><b>Symbol</b></td>
77+
<td style="text-align:center"><b>Description</b></td>
78+
<td style="text-align:center"><b>Format</b></td>
79+
</tr>
80+
<tr>
81+
<td rowspan="4" style="text-align:center"><b>Input</b></td>
82+
<td style="text-align:center"><TT>f</TT></td>
83+
<td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{f}(t,\mathbf{y})" title="" /></td>
84+
<td>multivariate, vector-valued function (<img
85+
src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{f}:\mathbb{R}\times\mathbb{R}^{p}\rightarrow\mathbb{R}^{p}"
86+
title="" />) defining the ordinary differential equation <img src="https://latex.codecogs.com/svg.latex?\inline&space;\frac{d\mathbf{y}}{dt}=\mathbf{f}(t,\mathbf{y})" title="" />
87+
<BR> - inputs to <TT>f</TT> are the current time (<TT>t</TT>, 1×1 double) and the current state vector (<TT>y</TT>, p×1 double)
88+
<BR> - output of <TT>f</TT> is the state vector derivative (<TT>dydt</TT>, p×1 double) at the current time/state</td>
89+
<td style="text-align:center">1×1<BR>function_handle</td>
90+
</tr>
91+
<tr>
92+
<td style="text-align:center"><TT>t</TT></td>
93+
<td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\inline&space;t_{n}" title="" /></td>
94+
<td>current sample time</td>
95+
<td style="text-align:center">1×1<BR>double</td>
96+
</tr>
97+
<tr>
98+
<td style="text-align:center"><TT>y</TT></td>
99+
<td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{y}_{n}=\mathbf{y}(t_{n})" title="" /></td>
100+
<td>state vector (i.e. solution) at the current sample time</td>
101+
<td style="text-align:center">p×1<BR>double</td>
102+
</tr>
103+
<tr>
104+
<td style="text-align:center"><TT>h</TT></td>
105+
<td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\inline&space;h" title="h" /></td>
106+
<td>step size</td>
107+
<td style="text-align:center">1×1<BR>double</td>
108+
</tr>
109+
<tr>
110+
<td rowspan="1" style="text-align:center"><b>Output</b></td>
111+
<td style="text-align:center"><TT>y_next</TT></td>
112+
<td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\mathbf{y}_{n+1}=\mathbf{y}(t_{n+1})" title="" /></td>
113+
<td>state vector (i.e. solution) at the next sample time, <img src="https://latex.codecogs.com/svg.latex?t_{n+1}=t_{n}+h" title="" /></td>
114+
<td style="text-align:center">p×1<BR>double</td>
115+
</tr>
116+
</table>
117+
</p><h2 id="4">Example</h2><p><i>Consider the initial value problem</i></p><p><img src="RK1_euler_doc_eq12868018520907325398.png" alt="$$\frac{dy}{dt}=y,\quad y(2)=3$$" style="width:89px;height:23px;"></p><p><i>Find the solution <img src="RK1_euler_doc_eq17784377804790973832.png" alt="$y(t)$" style="width:18px;height:11px;"> until <img src="RK1_euler_doc_eq08325516970591449802.png" alt="$t=10$" style="width:29px;height:8px;"> using <tt>RK1_euler</tt>. Then, compare your result to the solution found by <tt>oderk</tt> using the Euler method.</i></p><p>First, let's define our ODE (<img src="RK1_euler_doc_eq15749537601348477239.png" alt="$\frac{dy}{dt}=f(t,y)$" style="width:53px;height:15px;">) and initial condition in MATLAB.</p><pre class="codeinput">f = @(t,y) y;
118+
y2 = 3;
119+
</pre><p>Let's define a time vector between <img src="RK1_euler_doc_eq11906475312356421895.png" alt="$t=2$" style="width:24px;height:8px;"> and <img src="RK1_euler_doc_eq08325516970591449802.png" alt="$t=10$" style="width:29px;height:8px;"> with a spacing of <img src="RK1_euler_doc_eq10072498013177321932.png" alt="$h=0.01$" style="width:40px;height:8px;">.</p><pre class="codeinput">h = 0.01;
120+
t = (2:h:10)';
121+
</pre><p>Solving for <img src="RK1_euler_doc_eq17784377804790973832.png" alt="$y(t)$" style="width:18px;height:11px;"> using <tt>RK1_euler</tt> and comparing the result to the result obtained using <tt>oderk</tt> with the Euler method,</p><pre class="codeinput"><span class="comment">% preallocate vector to store solution</span>
122+
y = zeros(size(t));
123+
124+
<span class="comment">% store initial condition</span>
125+
y(1) = y2;
126+
127+
<span class="comment">% solving using "RK1_euler"</span>
128+
<span class="keyword">for</span> i = 1:(length(t)-1)
129+
y(i+1) = RK1_euler(f,t(i),y(i),h);
130+
<span class="keyword">end</span>
131+
132+
<span class="comment">% solving using "oderk"</span>
133+
[t_oderk,y_oderk] = oderk(f,[2,10],y2,h,<span class="string">'RK1_euler'</span>);
134+
135+
<span class="comment">% maximum absolute error between the two results</span>
136+
max(abs(y_oderk-y))
137+
</pre><pre class="codeoutput">
138+
ans =
139+
140+
0
141+
142+
</pre><p>As expected, the two methods obtain identical results.</p><h2 id="8">See also</h2><p><a href="RK2_doc.html"><tt>RK2</tt></a> | <a href="RK2_heun_doc.html"><tt>RK2_heun</tt></a> | <a href="RK2_ralston_doc.html"><tt>RK2_ralston</tt></a> | <a href="RK3_doc.html"><tt>RK3</tt></a> | <a href="RK3_heun_doc.html"><tt>RK3_heun</tt></a> | <a href="RK3_ralston_doc.html"><tt>RK3_ralston</tt></a> | <a href="SSPRK3_doc.html"><tt>SSPRK3</tt></a> | <a href="RK4_doc.html"><tt>RK4</tt></a> | <a href="RK4_ralston_doc.html"><tt>RK4_ralston</tt></a> | <a href="RK4_38_doc.html"><tt>RK4_38</tt></a></p><p class="footer"><br><a href="https://www.mathworks.com/products/matlab/">Published with MATLAB&reg; R2021b</a><br></p></div><!--
143+
##### SOURCE BEGIN #####
144+
%% |RK1_euler|
145+
% Propagates the state vector forward one time step using the Euler
146+
% (first-order) method.
147+
%
148+
% <index.html Back to ODE Solver Toolbox Contents>.
149+
%% Syntax
150+
% y_next = RK1_euler(f,t,y,h)
151+
%% Description
152+
% |y_next = RK1_euler(f,t,y,h)| returns the state vector at the next
153+
% sample time, |y_next|, given the current state vector |y| at time |t|,
154+
% the function |f(t,y)| defining the ODE
155+
% $\dot{\mathbf{y}}=\mathbf{f}(t,\mathbf{y})$, and the step size |h|.
156+
%% Input/Output Parameters
157+
% <html>
158+
% <table border=1>
159+
% <tr>
160+
% <td></td>
161+
% <td style="text-align:center"><b>Variable</b></td>
162+
% <td style="text-align:center"><b>Symbol</b></td>
163+
% <td style="text-align:center"><b>Description</b></td>
164+
% <td style="text-align:center"><b>Format</b></td>
165+
% </tr>
166+
% <tr>
167+
% <td rowspan="4" style="text-align:center"><b>Input</b></td>
168+
% <td style="text-align:center"><TT>f</TT></td>
169+
% <td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{f}(t,\mathbf{y})" title="" /></td>
170+
% <td>multivariate, vector-valued function (<img
171+
% src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{f}:\mathbb{R}\times\mathbb{R}^{p}\rightarrow\mathbb{R}^{p}"
172+
% title="" />) defining the ordinary differential equation <img src="https://latex.codecogs.com/svg.latex?\inline&space;\frac{d\mathbf{y}}{dt}=\mathbf{f}(t,\mathbf{y})" title="" />
173+
% <BR> - inputs to <TT>f</TT> are the current time (<TT>t</TT>, 1×1 double) and the current state vector (<TT>y</TT>, p×1 double)
174+
% <BR> - output of <TT>f</TT> is the state vector derivative (<TT>dydt</TT>, p×1 double) at the current time/state</td>
175+
% <td style="text-align:center">1×1<BR>function_handle</td>
176+
% </tr>
177+
% <tr>
178+
% <td style="text-align:center"><TT>t</TT></td>
179+
% <td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\inline&space;t_{n}" title="" /></td>
180+
% <td>current sample time</td>
181+
% <td style="text-align:center">1×1<BR>double</td>
182+
% </tr>
183+
% <tr>
184+
% <td style="text-align:center"><TT>y</TT></td>
185+
% <td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\inline&space;\mathbf{y}_{n}=\mathbf{y}(t_{n})" title="" /></td>
186+
% <td>state vector (i.e. solution) at the current sample time</td>
187+
% <td style="text-align:center">p×1<BR>double</td>
188+
% </tr>
189+
% <tr>
190+
% <td style="text-align:center"><TT>h</TT></td>
191+
% <td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\inline&space;h" title="h" /></td>
192+
% <td>step size</td>
193+
% <td style="text-align:center">1×1<BR>double</td>
194+
% </tr>
195+
% <tr>
196+
% <td rowspan="1" style="text-align:center"><b>Output</b></td>
197+
% <td style="text-align:center"><TT>y_next</TT></td>
198+
% <td style="text-align:center"><img src="https://latex.codecogs.com/svg.latex?\mathbf{y}_{n+1}=\mathbf{y}(t_{n+1})" title="" /></td>
199+
% <td>state vector (i.e. solution) at the next sample time, <img src="https://latex.codecogs.com/svg.latex?t_{n+1}=t_{n}+h" title="" /></td>
200+
% <td style="text-align:center">p×1<BR>double</td>
201+
% </tr>
202+
% </table>
203+
% </html>
204+
%% Example
205+
% _Consider the initial value problem_
206+
%
207+
% $$\frac{dy}{dt}=y,\quad y(2)=3$$
208+
%
209+
% _Find the solution $y(t)$ until $t=10$ using |RK1_euler|. Then, compare
210+
% your result to the solution found by |oderk| using the Euler method._
211+
%
212+
% First, let's define our ODE ($\frac{dy}{dt}=f(t,y)$) and initial
213+
% condition in MATLAB.
214+
f = @(t,y) y;
215+
y2 = 3;
216+
%%
217+
% Let's define a time vector between $t=2$ and $t=10$ with a spacing of
218+
% $h=0.01$.
219+
h = 0.01;
220+
t = (2:h:10)';
221+
%%
222+
% Solving for $y(t)$ using |RK1_euler| and comparing the result to the
223+
% result obtained using |oderk| with the Euler method,
224+
225+
% preallocate vector to store solution
226+
y = zeros(size(t));
227+
228+
% store initial condition
229+
y(1) = y2;
230+
231+
% solving using "RK1_euler"
232+
for i = 1:(length(t)-1)
233+
y(i+1) = RK1_euler(f,t(i),y(i),h);
234+
end
235+
236+
% solving using "oderk"
237+
[t_oderk,y_oderk] = oderk(f,[2,10],y2,h,'RK1_euler');
238+
239+
% maximum absolute error between the two results
240+
max(abs(y_oderk-y))
241+
%%
242+
% As expected, the two methods obtain identical results.
243+
%% See also
244+
% <RK2_doc.html |RK2|> |
245+
% <RK2_heun_doc.html |RK2_heun|> |
246+
% <RK2_ralston_doc.html |RK2_ralston|> |
247+
% <RK3_doc.html |RK3|> |
248+
% <RK3_heun_doc.html |RK3_heun|> |
249+
% <RK3_ralston_doc.html |RK3_ralston|> |
250+
% <SSPRK3_doc.html |SSPRK3|> |
251+
% <RK4_doc.html |RK4|> |
252+
% <RK4_ralston_doc.html |RK4_ralston|> |
253+
% <RK4_38_doc.html |RK4_38|>
254+
##### SOURCE END #####
255+
--></body></html>
1.01 KB
Loading
1.2 KB
Loading
844 Bytes
Loading
4.34 KB
Loading
2.23 KB
Loading
2.96 KB
Loading
1.23 KB
Loading

0 commit comments

Comments
 (0)