2020-06-28 18:07:29 +03: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" / >
< meta name = "generator" content = "Doxygen 1.8.18" / >
< meta name = "viewport" content = "width=device-width, initial-scale=1" / >
< title > Algorithms_in_C: numerical_methods/ode_semi_implicit_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 -->
<!-- Generated by Doxygen 1.8.18 -->
< script type = "text/javascript" >
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3& dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
/* @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/d99/ode__semi__implicit__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_semi_implicit_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/Semi-implicit_Euler_method" > semi implicit 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_semi_implicit_euler.c:< / div >
< div class = "dyncontent" >
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d9/d85/ode__semi__implicit__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-28 23:40:24 +03: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/d99/ode__semi__implicit__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/d99/ode__semi__implicit__euler_8c.html#a97075291390a68c262ed66e157a57eb4" title = "Problem statement for a system with first-order differential equations." > problem< / a > < br / > < / td > < / tr >
2020-06-28 18:07:29 +03: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/d99/ode__semi__implicit__euler_8c.html#a97075291390a68c262ed66e157a57eb4" > problem< / a > (const double *x, double *y, double *dy)< / td > < / tr >
2020-06-28 23:40:24 +03: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/d99/ode__semi__implicit__euler_8c.html#a97075291390a68c262ed66e157a57eb4" > More...< / a > < br / > < / td > < / tr >
2020-06-28 18:07:29 +03: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/d99/ode__semi__implicit__euler_8c.html#a8caee977b26888d34040b122e0e28e3a" > exact_solution< / a > (const double *x, double *y)< / td > < / tr >
2020-06-28 23:40:24 +03:00
< tr class = "memdesc:a8caee977b26888d34040b122e0e28e3a" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Exact solution of the problem. < a href = "../../d4/d99/ode__semi__implicit__euler_8c.html#a8caee977b26888d34040b122e0e28e3a" > More...< / a > < br / > < / td > < / tr >
2020-06-28 18:07:29 +03:00
< tr class = "separator:a8caee977b26888d34040b122e0e28e3a" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a720b7e995d2bbc615f94a2c7dbcf84eb" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d4/d99/ode__semi__implicit__euler_8c.html#a720b7e995d2bbc615f94a2c7dbcf84eb" > semi_implicit_euler_step< / a > (double dx, double *x, double *y, double *dy)< / td > < / tr >
< tr class = "memdesc:a720b7e995d2bbc615f94a2c7dbcf84eb" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Compute next step approximation using the semi-implicit-Euler method. < a href = "../../d4/d99/ode__semi__implicit__euler_8c.html#a720b7e995d2bbc615f94a2c7dbcf84eb" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:a720b7e995d2bbc615f94a2c7dbcf84eb" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:ad80059877222f885b549f2d0a3dc6b55" > < td class = "memItemLeft" align = "right" valign = "top" > double  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d4/d99/ode__semi__implicit__euler_8c.html#ad80059877222f885b549f2d0a3dc6b55" > semi_implicit_euler< / a > (double dx, double x0, double x_max, double *y, char save_to_file)< / td > < / tr >
< tr class = "memdesc:ad80059877222f885b549f2d0a3dc6b55" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Compute approximation using the semi-implicit-Euler method in the given limits. < a href = "../../d4/d99/ode__semi__implicit__euler_8c.html#ad80059877222f885b549f2d0a3dc6b55" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:ad80059877222f885b549f2d0a3dc6b55" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-06-28 23:40:24 +03: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/d99/ode__semi__implicit__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 18:07:29 +03: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/Semi-implicit_Euler_method" > semi implicit 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 18:30:37 +03:00
< p > The computation results are stored to a text file < code > semi_implicit_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_semi_implicit_euler.svg" alt = "Implementation solution" style = "pointer-events: none;" class = "inline" / > < / p >
2020-06-28 23:40:24 +03: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/d99/ode__semi__implicit__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 18:07:29 +03: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 >
2020-06-28 18:30:37 +03:00
< / div > <!-- fragment --> < p > < a href = "https://en.wikipedia.org/wiki/Van_der_Pol_oscillator" > < img src = "https://raw.githubusercontent.com/TheAlgorithms/C/docs/images/numerical_methods/van_der_pol_implicit_euler.svg" alt = "Van der Pol Oscillator solution" style = "pointer-events: none;" class = "inline" / > < / a > < / p >
2020-06-28 18:07:29 +03:00
< dl class = "section see" > < dt > See also< / dt > < dd > < a class = "el" href = "../../d4/d07/ode__forward__euler_8c.html" title = "Solve a multivariable first order ordinary differential equation (ODEs) using forward Euler method" > ode_forward_euler.c< / a > , < 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 > < / dd > < / dl >
2020-06-28 23:40:24 +03:00
< / div > < h2 class = "groupheader" > Function Documentation< / h2 >
2020-06-28 18:07:29 +03: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-28 23:40:24 +03:00
< p > Exact solution of the problem. < / p >
< p > Used for solution comparison.< / p >
2020-06-28 18:07:29 +03: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 = "l00072" > < / a > < span class = "lineno" > 72< / span >   {< / div >
< div class = "line" > < a name = "l00073" > < / a > < span class = "lineno" > 73< / span >   y[0] = cos(x[0]);< / div >
< div class = "line" > < a name = "l00074" > < / a > < span class = "lineno" > 74< / span >   y[1] = -sin(x[0]);< / div >
< div class = "line" > < a name = "l00075" > < / a > < span class = "lineno" > 75< / span >   }< / div >
< / div > <!-- fragment -->
< / 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-28 23:40:24 +03: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 18:07:29 +03: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 = "l00059" > < / a > < span class = "lineno" > 59< / span >   {< / div >
2020-06-28 18:30:37 +03:00
< div class = "line" > < a name = "l00060" > < / a > < span class = "lineno" > 60< / 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 = "l00061" > < / a > < span class = "lineno" > 61< / span >   dy[0] = y[1]; < span class = "comment" > // x dot< / span > < / div >
< div class = "line" > < a name = "l00062" > < / a > < span class = "lineno" > 62< / span >   dy[1] = -omega * omega * y[0]; < span class = "comment" > // y dot< / span > < / div >
2020-06-28 18:07:29 +03:00
< div class = "line" > < a name = "l00063" > < / a > < span class = "lineno" > 63< / span >   }< / div >
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "ad80059877222f885b549f2d0a3dc6b55" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#ad80059877222f885b549f2d0a3dc6b55" > ◆ < / a > < / span > semi_implicit_euler()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > double semi_implicit_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 semi-implicit-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 >
< div class = "fragment" > < div class = "line" > < a name = "l00111" > < / a > < span class = "lineno" > 111< / span >   {< / div >
< div class = "line" > < a name = "l00112" > < / a > < span class = "lineno" > 112< / span >   < span class = "keywordtype" > double< / span > dy[< a class = "code" href = "../../d4/d99/ode__semi__implicit__euler_8c.html#a9ceb646336224ee890a269d0b4600d09" > order< / a > ];< / 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 >   FILE *fp = NULL;< / div >
< div class = "line" > < a name = "l00115" > < / a > < span class = "lineno" > 115< / span >   < span class = "keywordflow" > if< / span > (save_to_file)< / div >
< div class = "line" > < a name = "l00116" > < / a > < span class = "lineno" > 116< / span >   {< / div >
< div class = "line" > < a name = "l00117" > < / a > < span class = "lineno" > 117< / span >   fp = fopen(< span class = "stringliteral" > " semi_implicit_euler.csv" < / span > , < span class = "stringliteral" > " w+" < / span > );< / div >
< div class = "line" > < a name = "l00118" > < / a > < span class = "lineno" > 118< / span >   < span class = "keywordflow" > if< / span > (fp == NULL)< / 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 >   perror(< span class = "stringliteral" > " Error! " < / span > );< / div >
< div class = "line" > < a name = "l00121" > < / a > < span class = "lineno" > 121< / span >   < span class = "keywordflow" > return< / span > -1;< / div >
< div class = "line" > < a name = "l00122" > < / a > < span class = "lineno" > 122< / span >   }< / div >
< div class = "line" > < a name = "l00123" > < / a > < span class = "lineno" > 123< / span >   }< / div >
< div class = "line" > < a name = "l00124" > < / a > < span class = "lineno" > 124< / span >   < / div >
< div class = "line" > < a name = "l00125" > < / a > < span class = "lineno" > 125< / span >   < span class = "comment" > /* start integration */< / span > < / div >
< div class = "line" > < a name = "l00126" > < / a > < span class = "lineno" > 126< / span >   clock_t t1 = clock();< / div >
< div class = "line" > < a name = "l00127" > < / a > < span class = "lineno" > 127< / span >   < span class = "keywordtype" > double< / span > x = x0;< / div >
2020-06-28 18:30:37 +03:00
< div class = "line" > < a name = "l00128" > < / a > < span class = "lineno" > 128< / span >   < span class = "keywordflow" > do< / span > < span class = "comment" > // iterate for each step of independent variable< / span > < / div >
2020-06-28 18:07:29 +03:00
< div class = "line" > < a name = "l00129" > < / a > < span class = "lineno" > 129< / span >   {< / div >
< div class = "line" > < a name = "l00130" > < / a > < span class = "lineno" > 130< / span >   < span class = "keywordflow" > if< / span > (save_to_file & & fp)< / div >
2020-06-28 18:30:37 +03:00
< div class = "line" > < a name = "l00131" > < / a > < span class = "lineno" > 131< / 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 = "l00132" > < / a > < span class = "lineno" > 132< / span >   < a class = "code" href = "../../d4/d99/ode__semi__implicit__euler_8c.html#a720b7e995d2bbc615f94a2c7dbcf84eb" > semi_implicit_euler_step< / a > (dx, & x, y, dy); < span class = "comment" > // perform integration< / span > < / div >
< div class = "line" > < a name = "l00133" > < / a > < span class = "lineno" > 133< / span >   x += dx; < span class = "comment" > // update step< / span > < / div >
< div class = "line" > < a name = "l00134" > < / a > < span class = "lineno" > 134< / span >   } < span class = "keywordflow" > while< / span > (x < = x_max); < span class = "comment" > // till upper limit of independent variable< / span > < / div >
2020-06-28 18:07:29 +03:00
< div class = "line" > < a name = "l00135" > < / a > < span class = "lineno" > 135< / span >   < span class = "comment" > /* end of integration */< / span > < / div >
< div class = "line" > < a name = "l00136" > < / a > < span class = "lineno" > 136< / span >   clock_t t2 = clock();< / div >
< div class = "line" > < a name = "l00137" > < / a > < span class = "lineno" > 137< / span >   < / div >
< div class = "line" > < a name = "l00138" > < / a > < span class = "lineno" > 138< / span >   < span class = "keywordflow" > if< / span > (save_to_file & & fp)< / div >
< div class = "line" > < a name = "l00139" > < / a > < span class = "lineno" > 139< / span >   fclose(fp);< / div >
< div class = "line" > < a name = "l00140" > < / a > < span class = "lineno" > 140< / span >   < / div >
< div class = "line" > < a name = "l00141" > < / a > < span class = "lineno" > 141< / span >   < span class = "keywordflow" > return< / span > (< span class = "keywordtype" > double< / span > )(t2 - t1) / CLOCKS_PER_SEC;< / div >
< div class = "line" > < a name = "l00142" > < / a > < span class = "lineno" > 142< / span >   }< / div >
< / 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/d99/ode__semi__implicit__euler_8c_ad80059877222f885b549f2d0a3dc6b55_cgraph.svg" width = "474" 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 = "a720b7e995d2bbc615f94a2c7dbcf84eb" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a720b7e995d2bbc615f94a2c7dbcf84eb" > ◆ < / a > < / span > semi_implicit_euler_step()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void semi_implicit_euler_step < / 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 > 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 semi-implicit-Euler method. < / 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 \(y_n+\frac{1}{2}dx\,f\left(x_n,y_n\right)\) < / td > < / tr >
< / table >
< / dd >
< / dl >
< div class = "fragment" > < div class = "line" > < a name = "l00086" > < / a > < span class = "lineno" > 86< / span >   {< / div >
< div class = "line" > < a name = "l00087" > < / a > < span class = "lineno" > 87< / span >   < span class = "keywordtype" > int< / span > o;< / div >
< div class = "line" > < a name = "l00088" > < / a > < span class = "lineno" > 88< / span >   < / div >
2020-06-28 18:30:37 +03:00
< div class = "line" > < a name = "l00089" > < / a > < span class = "lineno" > 89< / span >   < a class = "code" href = "../../d4/d99/ode__semi__implicit__euler_8c.html#a97075291390a68c262ed66e157a57eb4" > problem< / a > (x, y, dy); < span class = "comment" > // update dy once< / span > < / div >
< div class = "line" > < a name = "l00090" > < / a > < span class = "lineno" > 90< / span >   y[0] += dx * dy[0]; < span class = "comment" > // update y0< / span > < / div >
2020-06-28 18:07:29 +03:00
< div class = "line" > < a name = "l00091" > < / a > < span class = "lineno" > 91< / span >   < / div >
2020-06-28 18:30:37 +03:00
< div class = "line" > < a name = "l00092" > < / a > < span class = "lineno" > 92< / span >   < a class = "code" href = "../../d4/d99/ode__semi__implicit__euler_8c.html#a97075291390a68c262ed66e157a57eb4" > problem< / a > (x, y, dy); < span class = "comment" > // update dy once more< / span > < / div >
2020-06-28 18:07:29 +03:00
< div class = "line" > < a name = "l00093" > < / a > < span class = "lineno" > 93< / span >   < / div >
< div class = "line" > < a name = "l00094" > < / a > < span class = "lineno" > 94< / span >   < span class = "keywordflow" > for< / span > (o = 1; o < < a class = "code" href = "../../d4/d99/ode__semi__implicit__euler_8c.html#a9ceb646336224ee890a269d0b4600d09" > order< / a > ; o++)< / div >
2020-06-28 18:30:37 +03:00
< div class = "line" > < a name = "l00095" > < / a > < span class = "lineno" > 95< / span >   y[o] += dx * dy[o]; < span class = "comment" > // update remaining using new dy< / span > < / div >
2020-06-28 18:07:29 +03:00
< div class = "line" > < a name = "l00096" > < / a > < span class = "lineno" > 96< / span >   *x += dx;< / div >
< div class = "line" > < a name = "l00097" > < / a > < span class = "lineno" > 97< / span >   }< / div >
< / 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/d99/ode__semi__implicit__euler_8c_a720b7e995d2bbc615f94a2c7dbcf84eb_cgraph.svg" width = "292" 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 >
< / div > <!-- contents -->
< / div > <!-- doc - content -->
2020-06-28 23:40:24 +03:00
< div class = "ttc" id = "aode__semi__implicit__euler_8c_html_a97075291390a68c262ed66e157a57eb4" > < div class = "ttname" > < a href = "../../d4/d99/ode__semi__implicit__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_semi_implicit_euler.c:58< / div > < / div >
< div class = "ttc" id = "aode__semi__implicit__euler_8c_html_a9ceb646336224ee890a269d0b4600d09" > < div class = "ttname" > < a href = "../../d4/d99/ode__semi__implicit__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_semi_implicit_euler.c:47< / div > < / div >
2020-06-28 18:07:29 +03:00
< div class = "ttc" id = "aode__semi__implicit__euler_8c_html_a720b7e995d2bbc615f94a2c7dbcf84eb" > < div class = "ttname" > < a href = "../../d4/d99/ode__semi__implicit__euler_8c.html#a720b7e995d2bbc615f94a2c7dbcf84eb" > semi_implicit_euler_step< / a > < / div > < div class = "ttdeci" > void semi_implicit_euler_step(double dx, double *x, double *y, double *dy)< / div > < div class = "ttdoc" > Compute next step approximation using the semi-implicit-Euler method.< / div > < div class = "ttdef" > < b > Definition:< / b > ode_semi_implicit_euler.c:85< / div > < / div >
<!-- 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/d99/ode__semi__implicit__euler_8c.html" > ode_semi_implicit_euler.c< / a > < / li >
2020-06-28 18:30:37 +03:00
< li class = "footer" > Generated by
2020-06-28 18:07:29 +03:00
< a href = "http://www.doxygen.org/index.html" >
< img class = "footer" src = "../../doxygen.png" alt = "doxygen" / > < / a > 1.8.18 < / li >
< / ul >
< / div >
< / body >
< / html >