Heun's method for Euler's solution

12 ビュー (過去 30 日間)
Sachintha Alwis Weerasinghe
Sachintha Alwis Weerasinghe 2017 年 3 月 23 日
コメント済み: Jan 2017 年 3 月 23 日
This code solves y'(t)=-2*y(t)+t with y(0)=1 using Euler method
% Initial Condition
y0 = 1;
h = 0.2;
% t goes from 0 to 3 seconds.
t = 0:h:3;
% Preallocate array (good coding practice)
y_euler = zeros(size(t));
% Initial condition gives solution at t=0.
y_euler(1) = y0;
% Solving the equation via Euler's method
for i=1:(length(t)-1)
k1 = -2*y_euler(i)+t(i); % Previous approx for y gives approx for derivative
y_euler(i+1) = y_euler(i) + h*k1; % Approximate solution for next value of y
end
  1 件のコメント
Jan
Jan 2017 年 3 月 23 日
Fine. What is your question?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by