2020-06-28 23:07:29 +08:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv = "Content-Type" content = "text/xhtml;charset=UTF-8" / >
< meta http-equiv = "X-UA-Compatible" content = "IE=9" / >
2021-02-06 03:52:57 +08:00
< meta name = "generator" content = "Doxygen 1.9.1" / >
2020-06-28 23:07:29 +08:00
< meta name = "viewport" content = "width=device-width, initial-scale=1" / >
< title > Algorithms_in_C: numerical_methods/ode_forward_euler.c File Reference< / title >
< link href = "../../tabs.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "../../jquery.js" > < / script >
< script type = "text/javascript" src = "../../dynsections.js" > < / script >
< link href = "../../navtree.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "../../resize.js" > < / script >
< script type = "text/javascript" src = "../../navtreedata.js" > < / script >
< script type = "text/javascript" src = "../../navtree.js" > < / script >
< link href = "../../search/search.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "../../search/searchdata.js" > < / script >
< script type = "text/javascript" src = "../../search/search.js" > < / script >
< script type = "text/x-mathjax-config" >
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
< / script >
< script type = "text/javascript" async = "async" src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js" > < / script >
< link href = "../../doxygen.css" rel = "stylesheet" type = "text/css" / >
< / head >
< body >
< div id = "top" > <!-- do not remove this div, it is closed by doxygen! -->
< div id = "titlearea" >
< table cellspacing = "0" cellpadding = "0" >
< tbody >
< tr style = "height: 56px;" >
< td id = "projectalign" style = "padding-left: 0.5em;" >
< div id = "projectname" > Algorithms_in_C
  < span id = "projectnumber" > 1.0.0< / span >
< / div >
< div id = "projectbrief" > Set of algorithms implemented in C.< / div >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
<!-- end header part -->
2021-02-06 03:52:57 +08:00
<!-- Generated by Doxygen 1.9.1 -->
2020-06-28 23:07:29 +08:00
< script type = "text/javascript" >
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3& dn=gpl-2.0.txt GPL-v2 */
2021-02-06 03:52:57 +08:00
var searchBox = new SearchBox("searchBox", "../../search",false,'Search','.html');
2020-06-28 23:07:29 +08:00
/* @license-end */
< / script >
< script type = "text/javascript" src = "../../menudata.js" > < / script >
< script type = "text/javascript" src = "../../menu.js" > < / script >
< script type = "text/javascript" >
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3& dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */< / script >
< div id = "main-nav" > < / div >
< / div > <!-- top -->
< div id = "side-nav" class = "ui-resizable side-nav-resizable" >
< div id = "nav-tree" >
< div id = "nav-tree-contents" >
< div id = "nav-sync" class = "sync" > < / div >
< / div >
< / div >
< div id = "splitbar" style = "-moz-user-select:none;"
class="ui-resizable-handle">
< / div >
< / div >
< script type = "text/javascript" >
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3& dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('d4/d07/ode__forward__euler_8c.html','../../'); initResizable(); });
/* @license-end */
< / script >
< div id = "doc-content" >
<!-- window showing the filter options -->
< div id = "MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
< / div >
<!-- iframe showing the search results (closed by default) -->
< div id = "MSearchResultsWindow" >
< iframe src = "javascript:void(0)" frameborder = "0"
name="MSearchResults" id="MSearchResults">
< / iframe >
< / div >
< div class = "header" >
< div class = "summary" >
< a href = "#define-members" > Macros< / a > |
< a href = "#func-members" > Functions< / a > < / div >
< div class = "headertitle" >
< div class = "title" > ode_forward_euler.c File Reference< / div > < / div >
< / div > <!-- header -->
< div class = "contents" >
< p > Solve a multivariable first order < a href = "https://en.wikipedia.org/wiki/Ordinary_differential_equation" > ordinary differential equation (ODEs)< / a > using < a href = "https://en.wikipedia.org/wiki/Numerical_methods_for_ordinary_differential_equations#Euler_method" > forward Euler method< / a >
< a href = "#details" > More...< / a > < / p >
< div class = "textblock" > < code > #include < math.h> < / code > < br / >
< code > #include < stdio.h> < / code > < br / >
< code > #include < stdlib.h> < / code > < br / >
< code > #include < time.h> < / code > < br / >
< / div > < div class = "textblock" > < div class = "dynheader" >
Include dependency graph for ode_forward_euler.c:< / div >
< div class = "dyncontent" >
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d1/d6c/ode__forward__euler_8c__incl.svg" width = "331" height = "127" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
< / div >
< / div >
< / div > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a name = "define-members" > < / a >
Macros< / h2 > < / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memitem:a9ceb646336224ee890a269d0b4600d09" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a9ceb646336224ee890a269d0b4600d09" > < / a >
#define  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html#a9ceb646336224ee890a269d0b4600d09" > order< / a >       2< / td > < / tr >
< tr class = "memdesc:a9ceb646336224ee890a269d0b4600d09" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > number of dependent variables in < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html#a97075291390a68c262ed66e157a57eb4" title = "Problem statement for a system with first-order differential equations." > problem< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a9ceb646336224ee890a269d0b4600d09" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a name = "func-members" > < / a >
Functions< / h2 > < / td > < / tr >
< tr class = "memitem:a97075291390a68c262ed66e157a57eb4" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html#a97075291390a68c262ed66e157a57eb4" > problem< / a > (const double *x, double *y, double *dy)< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:a97075291390a68c262ed66e157a57eb4" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Problem statement for a system with first-order differential equations. < a href = "../../d4/d07/ode__forward__euler_8c.html#a97075291390a68c262ed66e157a57eb4" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a97075291390a68c262ed66e157a57eb4" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a8caee977b26888d34040b122e0e28e3a" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html#a8caee977b26888d34040b122e0e28e3a" > exact_solution< / a > (const double *x, double *y)< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:a8caee977b26888d34040b122e0e28e3a" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Exact solution of the problem. < a href = "../../d4/d07/ode__forward__euler_8c.html#a8caee977b26888d34040b122e0e28e3a" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a8caee977b26888d34040b122e0e28e3a" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:ae6c9413953c8d9d4bc9e374b29586350" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html#ae6c9413953c8d9d4bc9e374b29586350" > forward_euler_step< / a > (const double dx, const double *x, double *y, double *dy)< / td > < / tr >
< tr class = "memdesc:ae6c9413953c8d9d4bc9e374b29586350" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Compute next step approximation using the forward-Euler method. < a href = "../../d4/d07/ode__forward__euler_8c.html#ae6c9413953c8d9d4bc9e374b29586350" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:ae6c9413953c8d9d4bc9e374b29586350" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:aaf88ad8f9f7c39fc38f3f03d6fea9df9" > < td class = "memItemLeft" align = "right" valign = "top" > double  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html#aaf88ad8f9f7c39fc38f3f03d6fea9df9" > forward_euler< / a > (double dx, double x0, double x_max, double *y, char save_to_file)< / td > < / tr >
< tr class = "memdesc:aaf88ad8f9f7c39fc38f3f03d6fea9df9" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Compute approximation using the forward-Euler method in the given limits. < a href = "../../d4/d07/ode__forward__euler_8c.html#aaf88ad8f9f7c39fc38f3f03d6fea9df9" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:aaf88ad8f9f7c39fc38f3f03d6fea9df9" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memitem:a0ddf1224851353fc92bfbff6f499fa97" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a0ddf1224851353fc92bfbff6f499fa97" > < / a >
int  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html#a0ddf1224851353fc92bfbff6f499fa97" > main< / a > (int argc, char *argv[])< / td > < / tr >
< tr class = "memdesc:a0ddf1224851353fc92bfbff6f499fa97" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Main Function. < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a0ddf1224851353fc92bfbff6f499fa97" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table >
< a name = "details" id = "details" > < / a > < h2 class = "groupheader" > Detailed Description< / h2 >
< div class = "textblock" > < p > Solve a multivariable first order < a href = "https://en.wikipedia.org/wiki/Ordinary_differential_equation" > ordinary differential equation (ODEs)< / a > using < a href = "https://en.wikipedia.org/wiki/Numerical_methods_for_ordinary_differential_equations#Euler_method" > forward Euler method< / a > < / p >
< dl class = "section author" > < dt > Authors< / dt > < dd > < a href = "https://github.com/kvedala" > Krishna Vedala< / a > < / dd > < / dl >
< p > The ODE being solved is: < / p > < p class = "formulaDsp" >
\begin{eqnarray*} \dot{u} & =& v\\ \dot{v} & =& -\omega^2 u\\ \omega & =& 1\\ [x_0, u_0, v_0] & =& [0,1,0]\qquad\ldots\text{(initial values)} \end{eqnarray*}
< / p >
< p > The exact solution for the above problem is: < / p > < p class = "formulaDsp" >
\begin{eqnarray*} u(x) & =& \cos(x)\\ v(x) & =& -\sin(x)\\ \end{eqnarray*}
< / p >
2020-06-28 23:30:37 +08:00
< p > The computation results are stored to a text file < code > forward_euler.csv< / code > and the exact soltuion results in < code > exact.csv< / code > for comparison. < img src = "https://raw.githubusercontent.com/TheAlgorithms/C/docs/images/numerical_methods/ode_forward_euler.svg" alt = "Implementation solution" style = "pointer-events: none;" class = "inline" / > < / p >
2020-06-29 04:40:24 +08:00
< p > To implement < a href = "https://en.wikipedia.org/wiki/Van_der_Pol_oscillator" > Van der Pol oscillator< / a > , change the < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html#a97075291390a68c262ed66e157a57eb4" title = "Problem statement for a system with first-order differential equations." > problem< / a > function to: < / p > < div class = "fragment" > < div class = "line" > < span class = "keyword" > const< / span > < span class = "keywordtype" > double< / span > mu = 2.0;< / div >
2020-06-28 23:07:29 +08:00
< div class = "line" > dy[0] = y[1];< / div >
< div class = "line" > dy[1] = mu * (1.f - y[0] * y[0]) * y[1] - y[0];< / div >
2021-02-06 03:52:57 +08:00
< / div > <!-- fragment --> < dl class = "section see" > < dt > See also< / dt > < dd > < a class = "el" href = "../../d1/dc2/ode__midpoint__euler_8c.html" title = "Solve a multivariable first order ordinary differential equation (ODEs) using midpoint Euler method" > ode_midpoint_euler.c< / a > , < a class = "el" href = "../../d4/d99/ode__semi__implicit__euler_8c.html" title = "Solve a multivariable first order ordinary differential equation (ODEs) using semi implicit Euler met..." > ode_semi_implicit_euler.c< / a > < / dd > < / dl >
2020-06-29 04:40:24 +08:00
< / div > < h2 class = "groupheader" > Function Documentation< / h2 >
2020-06-28 23:07:29 +08:00
< a id = "a8caee977b26888d34040b122e0e28e3a" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a8caee977b26888d34040b122e0e28e3a" > ◆ < / a > < / span > exact_solution()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void exact_solution < / td >
< td > (< / td >
< td class = "paramtype" > const double *  < / td >
< td class = "paramname" > < em > x< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double *  < / td >
< td class = "paramname" > < em > y< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< p > Exact solution of the problem. < / p >
< p > Used for solution comparison.< / p >
2020-06-28 23:07:29 +08:00
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > x< / td > < td > independent variable < / td > < / tr >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > y< / td > < td > dependent variable < / td > < / tr >
< / table >
< / dd >
< / dl >
< div class = "fragment" > < div class = "line" > < a name = "l00069" > < / a > < span class = "lineno" > 69< / span >   {< / div >
< div class = "line" > < a name = "l00070" > < / a > < span class = "lineno" > 70< / span >   y[0] = cos(x[0]);< / div >
< div class = "line" > < a name = "l00071" > < / a > < span class = "lineno" > 71< / span >   y[1] = -sin(x[0]);< / div >
< div class = "line" > < a name = "l00072" > < / a > < span class = "lineno" > 72< / span >   }< / div >
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "aaf88ad8f9f7c39fc38f3f03d6fea9df9" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#aaf88ad8f9f7c39fc38f3f03d6fea9df9" > ◆ < / a > < / span > forward_euler()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > double forward_euler < / td >
< td > (< / td >
< td class = "paramtype" > double  < / td >
< td class = "paramname" > < em > dx< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double  < / td >
< td class = "paramname" > < em > x0< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double  < / td >
< td class = "paramname" > < em > x_max< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double *  < / td >
< td class = "paramname" > < em > y< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > char  < / td >
< td class = "paramname" > < em > save_to_file< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Compute approximation using the forward-Euler method in the given limits. < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > dx< / td > < td > step size < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > x0< / td > < td > initial value of independent variable < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > x_max< / td > < td > final value of independent variable < / td > < / tr >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > y< / td > < td > take \(y_n\) and compute \(y_{n+1}\) < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > save_to_file< / td > < td > flag to save results to a CSV file (1) or not (0) < / td > < / tr >
< / table >
< / dd >
< / dl >
< dl class = "section return" > < dt > Returns< / dt > < dd > time taken for computation in seconds < / dd > < / dl >
2020-06-28 23:30:37 +08:00
< div class = "fragment" > < div class = "line" > < a name = "l00101" > < / a > < span class = "lineno" > 101< / span >   {< / div >
< div class = "line" > < a name = "l00102" > < / a > < span class = "lineno" > 102< / span >   < span class = "keywordtype" > double< / span > dy[< a class = "code" href = "../../d4/d07/ode__forward__euler_8c.html#a9ceb646336224ee890a269d0b4600d09" > order< / a > ];< / div >
< div class = "line" > < a name = "l00103" > < / a > < span class = "lineno" > 103< / span >   < / div >
< div class = "line" > < a name = "l00104" > < / a > < span class = "lineno" > 104< / span >   FILE *fp = NULL;< / div >
< div class = "line" > < a name = "l00105" > < / a > < span class = "lineno" > 105< / span >   < span class = "keywordflow" > if< / span > (save_to_file)< / div >
< div class = "line" > < a name = "l00106" > < / a > < span class = "lineno" > 106< / span >   {< / div >
< div class = "line" > < a name = "l00107" > < / a > < span class = "lineno" > 107< / span >   fp = fopen(< span class = "stringliteral" > " forward_euler.csv" < / span > , < span class = "stringliteral" > " w+" < / span > );< / div >
< div class = "line" > < a name = "l00108" > < / a > < span class = "lineno" > 108< / span >   < span class = "keywordflow" > if< / span > (fp == NULL)< / div >
< div class = "line" > < a name = "l00109" > < / a > < span class = "lineno" > 109< / span >   {< / div >
< div class = "line" > < a name = "l00110" > < / a > < span class = "lineno" > 110< / span >   perror(< span class = "stringliteral" > " Error! " < / span > );< / div >
< div class = "line" > < a name = "l00111" > < / a > < span class = "lineno" > 111< / span >   < span class = "keywordflow" > return< / span > -1;< / div >
< div class = "line" > < a name = "l00112" > < / a > < span class = "lineno" > 112< / span >   }< / div >
< div class = "line" > < a name = "l00113" > < / a > < span class = "lineno" > 113< / span >   }< / div >
< div class = "line" > < a name = "l00114" > < / a > < span class = "lineno" > 114< / span >   < / div >
< div class = "line" > < a name = "l00115" > < / a > < span class = "lineno" > 115< / span >   < span class = "comment" > /* start integration */< / span > < / div >
< div class = "line" > < a name = "l00116" > < / a > < span class = "lineno" > 116< / span >   clock_t t1 = clock();< / div >
< div class = "line" > < a name = "l00117" > < / a > < span class = "lineno" > 117< / span >   < span class = "keywordtype" > double< / span > x = x0;< / div >
< div class = "line" > < a name = "l00118" > < / a > < span class = "lineno" > 118< / span >   < span class = "keywordflow" > do< / span > < span class = "comment" > // iterate for each step of independent variable< / span > < / div >
< div class = "line" > < a name = "l00119" > < / a > < span class = "lineno" > 119< / span >   {< / div >
< div class = "line" > < a name = "l00120" > < / a > < span class = "lineno" > 120< / span >   < span class = "keywordflow" > if< / span > (save_to_file & & fp)< / div >
< div class = "line" > < a name = "l00121" > < / a > < span class = "lineno" > 121< / span >   fprintf(fp, < span class = "stringliteral" > " %.4g,%.4g,%.4g\n" < / span > , x, y[0], y[1]); < span class = "comment" > // write to file< / span > < / div >
< div class = "line" > < a name = "l00122" > < / a > < span class = "lineno" > 122< / span >   < a class = "code" href = "../../d4/d07/ode__forward__euler_8c.html#ae6c9413953c8d9d4bc9e374b29586350" > forward_euler_step< / a > (dx, & x, y, dy); < span class = "comment" > // perform integration< / span > < / div >
< div class = "line" > < a name = "l00123" > < / a > < span class = "lineno" > 123< / span >   x += dx; < span class = "comment" > // update step< / span > < / div >
< div class = "line" > < a name = "l00124" > < / a > < span class = "lineno" > 124< / span >   } < span class = "keywordflow" > while< / span > (x < = x_max); < span class = "comment" > // till upper limit of independent variable< / span > < / div >
< div class = "line" > < a name = "l00125" > < / a > < span class = "lineno" > 125< / span >   < span class = "comment" > /* end of integration */< / span > < / div >
< div class = "line" > < a name = "l00126" > < / a > < span class = "lineno" > 126< / span >   clock_t t2 = clock();< / div >
< div class = "line" > < a name = "l00127" > < / a > < span class = "lineno" > 127< / span >   < / div >
< div class = "line" > < a name = "l00128" > < / a > < span class = "lineno" > 128< / span >   < span class = "keywordflow" > if< / span > (save_to_file & & fp)< / div >
< div class = "line" > < a name = "l00129" > < / a > < span class = "lineno" > 129< / span >   fclose(fp);< / div >
< div class = "line" > < a name = "l00130" > < / a > < span class = "lineno" > 130< / span >   < / div >
< div class = "line" > < a name = "l00131" > < / a > < span class = "lineno" > 131< / span >   < span class = "keywordflow" > return< / span > (< span class = "keywordtype" > double< / span > )(t2 - t1) / CLOCKS_PER_SEC;< / div >
< div class = "line" > < a name = "l00132" > < / a > < span class = "lineno" > 132< / span >   }< / div >
2021-02-06 03:52:57 +08:00
< div class = "ttc" id = "aode__forward__euler_8c_html_a9ceb646336224ee890a269d0b4600d09" > < div class = "ttname" > < a href = "../../d4/d07/ode__forward__euler_8c.html#a9ceb646336224ee890a269d0b4600d09" > order< / a > < / div > < div class = "ttdeci" > #define order< / div > < div class = "ttdoc" > number of dependent variables in problem< / div > < div class = "ttdef" > < b > Definition:< / b > ode_forward_euler.c:44< / div > < / div >
< div class = "ttc" id = "aode__forward__euler_8c_html_ae6c9413953c8d9d4bc9e374b29586350" > < div class = "ttname" > < a href = "../../d4/d07/ode__forward__euler_8c.html#ae6c9413953c8d9d4bc9e374b29586350" > forward_euler_step< / a > < / div > < div class = "ttdeci" > void forward_euler_step(const double dx, const double *x, double *y, double *dy)< / div > < div class = "ttdoc" > Compute next step approximation using the forward-Euler method.< / div > < div class = "ttdef" > < b > Definition:< / b > ode_forward_euler.c:82< / div > < / div >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d4/d07/ode__forward__euler_8c_aaf88ad8f9f7c39fc38f3f03d6fea9df9_cgraph.svg" width = "407" height = "38" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
< / div >
< / div >
< / div >
< / div >
< a id = "ae6c9413953c8d9d4bc9e374b29586350" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#ae6c9413953c8d9d4bc9e374b29586350" > ◆ < / a > < / span > forward_euler_step()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void forward_euler_step < / td >
< td > (< / td >
< td class = "paramtype" > const double  < / td >
< td class = "paramname" > < em > dx< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > const double *  < / td >
< td class = "paramname" > < em > x< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double *  < / td >
< td class = "paramname" > < em > y< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double *  < / td >
< td class = "paramname" > < em > dy< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Compute next step approximation using the forward-Euler method. < / p >
< p class = "formulaDsp" >
\[y_{n+1}=y_n + dx\cdot f\left(x_n,y_n\right)\]
< / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > dx< / td > < td > step size < / td > < / tr >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > x< / td > < td > take \(x_n\) and compute \(x_{n+1}\) < / td > < / tr >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > y< / td > < td > take \(y_n\) and compute \(y_{n+1}\) < / td > < / tr >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > dy< / td > < td > compute \(f\left(x_n,y_n\right)\) < / td > < / tr >
< / table >
< / dd >
< / dl >
< div class = "fragment" > < div class = "line" > < a name = "l00083" > < / a > < span class = "lineno" > 83< / span >   {< / div >
< div class = "line" > < a name = "l00084" > < / a > < span class = "lineno" > 84< / span >   < span class = "keywordtype" > int< / span > o;< / div >
< div class = "line" > < a name = "l00085" > < / a > < span class = "lineno" > 85< / span >   < a class = "code" href = "../../d4/d07/ode__forward__euler_8c.html#a97075291390a68c262ed66e157a57eb4" > problem< / a > (x, y, dy);< / div >
2020-06-28 23:30:37 +08:00
< div class = "line" > < a name = "l00086" > < / a > < span class = "lineno" > 86< / span >   < span class = "keywordflow" > for< / span > (o = 0; o < < a class = "code" href = "../../d4/d07/ode__forward__euler_8c.html#a9ceb646336224ee890a269d0b4600d09" > order< / a > ; o++) y[o] += dx * dy[o];< / div >
< div class = "line" > < a name = "l00087" > < / a > < span class = "lineno" > 87< / span >   }< / div >
2021-02-06 03:52:57 +08:00
< div class = "ttc" id = "aode__forward__euler_8c_html_a97075291390a68c262ed66e157a57eb4" > < div class = "ttname" > < a href = "../../d4/d07/ode__forward__euler_8c.html#a97075291390a68c262ed66e157a57eb4" > problem< / a > < / div > < div class = "ttdeci" > void problem(const double *x, double *y, double *dy)< / div > < div class = "ttdoc" > Problem statement for a system with first-order differential equations.< / div > < div class = "ttdef" > < b > Definition:< / b > ode_forward_euler.c:55< / div > < / div >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d4/d07/ode__forward__euler_8c_ae6c9413953c8d9d4bc9e374b29586350_cgraph.svg" width = "259" height = "38" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
< / div >
< / div >
< / div >
< / div >
< a id = "a97075291390a68c262ed66e157a57eb4" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a97075291390a68c262ed66e157a57eb4" > ◆ < / a > < / span > problem()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void problem < / td >
< td > (< / td >
< td class = "paramtype" > const double *  < / td >
< td class = "paramname" > < em > x< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double *  < / td >
< td class = "paramname" > < em > y< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > double *  < / td >
< td class = "paramname" > < em > dy< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< p > Problem statement for a system with first-order differential equations. < / p >
< p > Updates the system differential variables. < / p > < dl class = "section note" > < dt > Note< / dt > < dd > This function can be updated to and ode of any order.< / dd > < / dl >
2020-06-28 23:07:29 +08:00
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > x< / td > < td > independent variable(s) < / td > < / tr >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > y< / td > < td > dependent variable(s) < / td > < / tr >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > dy< / td > < td > first-derivative of dependent variable(s) < / td > < / tr >
< / table >
< / dd >
< / dl >
< div class = "fragment" > < div class = "line" > < a name = "l00056" > < / a > < span class = "lineno" > 56< / span >   {< / div >
2020-06-28 23:30:37 +08:00
< div class = "line" > < a name = "l00057" > < / a > < span class = "lineno" > 57< / span >   < span class = "keyword" > const< / span > < span class = "keywordtype" > double< / span > omega = 1.F; < span class = "comment" > // some const for the problem< / span > < / div >
< div class = "line" > < a name = "l00058" > < / a > < span class = "lineno" > 58< / span >   dy[0] = y[1]; < span class = "comment" > // x dot< / span > < / div >
< div class = "line" > < a name = "l00059" > < / a > < span class = "lineno" > 59< / span >   dy[1] = -omega * omega * y[0]; < span class = "comment" > // y dot< / span > < / div >
2020-06-28 23:07:29 +08:00
< div class = "line" > < a name = "l00060" > < / a > < span class = "lineno" > 60< / span >   }< / div >
< / div > <!-- fragment -->
< / div >
< / div >
< / div > <!-- contents -->
< / div > <!-- doc - content -->
<!-- start footer part -->
< div id = "nav-path" class = "navpath" > <!-- id is needed for treeview function! -->
< ul >
< li class = "navelem" > < a class = "el" href = "../../dir_9c6faab82c22511b50177aa2e38e2780.html" > numerical_methods< / a > < / li > < li class = "navelem" > < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html" > ode_forward_euler.c< / a > < / li >
2021-02-06 03:52:57 +08:00
< li class = "footer" > Generated by < a href = "https://www.doxygen.org/index.html" > < img class = "footer" src = "../../doxygen.svg" width = "104" height = "31" alt = "doxygen" / > < / a > 1.9.1 < / li >
2020-06-28 23:07:29 +08:00
< / ul >
< / div >
< / body >
< / html >