![]() |
Matlab - How to implement backward Euler's method?
<p>I am trying to implement these formulas:</p>
<h3>Forward Euler's method:</h3> <p><a href="https://i.stack.imgur.com/8myS0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8myS0.png" alt="enter image description here"></a></p> <p>this is what I have tried:</p> <pre class="lang-matlab prettyprint-override"><code>x_new = (speye(nv)+ dt * lambda * L) * x_old; </code></pre> <p>Is there anything wrong with this? How can I calculate this using <strong>sparse</strong> operation?</p> <h3>Backward Euler's method:</h3> <p><a href="https://i.stack.imgur.com/8kIu3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8kIu3.png" alt="enter image description here"></a></p> <p>I have tried this:</p> <pre class="lang-matlab prettyprint-override"><code>x_new = (speye(nv)- dt * lambda * L) \ x_old; </code></pre> <p>How to implement the backward part where the existing <code>x</code> is calculated based on the new <code>x</code>? Is it OK to use division?</p> <hr> <p><code>L</code> is a sparse matrix like this:</p> <pre class="lang-matlab prettyprint-override"><code>full(L) = -1.0000 0.2500 0.2500 0.2500 0.2500 0.3333 -1.0000 0.3333 0 0.3333 0.3333 0.3333 -1.0000 0.3333 0 0.3333 0 0.3333 -1.0000 0.3333 0.3333 0.3333 0 0.3333 -1.0000 </code></pre> <p>also for other variable we have something like this:</p> <pre class="lang-matlab prettyprint-override"><code>nv = 5; dt = 0.01; lambda = 0.5; x_old = [-4 0 5; 1 -5 5; 1 0 1; 1 5 5; 1 0 0] </code></pre> [url=https://stackoverflow.com/questions/59014837/matlab-how-to-implement-backward-eulers-method]More...[/url] |
所有时间均为北京时间。现在的时间是 19:41。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.