Help with creating a modified Euler method for a bungee jumping question
조회 수: 21 (최근 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!