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 methodfor k=1:Nend
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)
Best Answer