Help with creating a modified Euler method for a bungee jumping question
20 ビュー (過去 30 日間)
古いコメントを表示
We've been given Euler's method to solve a bungee jumping ODE, but we have to use a second order method (modified Euler, taylor2 or RK4). Here's the Euler's method:
function [t, y, v, h] = euler_bungee(T, n, g, C, K, L)
%euler_bungee Euler's method for the bungee jumping model
% [t, y, v, h] = euler_bungee(T, n, g, C, K, L) performs Euler's method on
% the bungee jumping model, taking n steps from t = 0 to t = T.
% The initial conditions are y(0) = 0 and v(0) = 0.
% The inputs g, C, K and L are parameters from the model (see project description).
% The outputs are the time array t, the solution arrays y and v, and the
% subinterval width h.
% Calculate subinterval width h
h = T / n;
% Create time array t
t = 0:h:T;
% Initialise solution arrays y and v
y = zeros(1,n+1);
v = zeros(1,n+1);
for j = 1:n
y(j+1) = y(j) + h*v(j);
v(j+1) = v(j) + h*(g - C*abs(v(j))*v(j) - max(0, K*(y(j) - L)));
end
end
Any chance anyone would know how to write a second order MATLAB function for this problem?
0 件のコメント
回答 (1 件)
James Tursa
2017 年 5 月 11 日
編集済み: James Tursa
2017 年 5 月 11 日
For Modified Euler's Method, e.g. this link:
https://mat.iitm.ac.in/home/sryedida/public_html/caimna/ode/euler/ie.html
Basically all you have to do is:
(1) Calculate the derivatives at your current point (you already have this)
(2) Take an Euler step with those derivatives and save the results in temporary variables
(3) Calculate the derivatives at the new point using these temporary variables
(4) Take a step from the original point using the average of (1) and (3) results.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Numerical Integration and Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!