Help with creating a modified Euler method for a bungee jumping question
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
James Tursa
le 11 Mai 2017
Modifié(e) : James Tursa
le 11 Mai 2017
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 commentaires
Voir également
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!