Solving a second order Differential equasion using Eulers Method
显示 更早的评论
I have to solve a second order differential equation using Euler's method (so not the ode45 command) and without using the Euler matlab shortcut. meaning i have write the loop myself.
i listed my parameter is a sturcture as follows:
%%This file defines the parameters of the parachutist
% use a structure to store the parameters
P.m = 80; % mass skydiver (kg)
P.h = 1000; % starting altitude (m)
P.g = 9.81; % gravity (m/s^2)
P.k = 1.4; % drag coefficient
and i defined the equations of motion for the skydiver as follows
function dx= Skydiver(t,w)
% Equations of motion for a skydiver
dx = zeros(2,1)
dx(1)=w(2);
dx(2)= -P.g+P.k/P.m*w(2)^2
In the following part i have to program the Euler's method to solve this problem, and eventually plot the altitude of the skydiver with respect to time and the speed of the skydiver with respect to time
clear all; % this helps to prevent unexpected problems
SkydiverParameters; % this runs the parameters script
%User-defined parameters
Tsim = 10; % simulate over Tsim seconds
h = 0.001; % step size
N= Tsim/h; % number of steps to simulate
x=zeros(2,1);
x(1)= 1000 % starthoogte
x(2)= 0 % startsnelheid
Simulation loop using Euler method
for k=1:N
end
so far i got this. but i cant figure out how to write the loop for the Euler's method Also, in the task description a pseude-code was given, but i cant figure it out.
Input: model function xdot = f(x) as defined above in step 3, simulation step size h, number of steps N to simulate, initial state x(1) Algorithm: for k from 1 to N x(k+1) = x(k) + h*f(x(k)) end Output: sequence of simulated states x(1), x(2), …, x(N+1)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 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!