odeEueler Explicit Eurlers method
Show older comments
Ok so I am working on a project and I will put the image of the problem statement and there must be somthing fundemental that I am doing incorrectly because I feel like this methodology is right for the problem
Here is my host file
%% Definining Initial Parameters for the Eueler
%yINI = [0;0]; %This describes the IC for the displacement and velocity
%h = [0.8 0.5 0.1]; %Given step sizes we will use in plots
%te = [0 8]; % ' Time Elapsed' from 0s-->8s our x-axis
function [t,y,ydot] = odeEULER(ODE1,ODE1,a,b,h,yINI)
%a - initial value for t
%b - last value of t
%h - step size
%yINI - y and y dot initial values
%Output variables- t,y,ydot
t(1) = 0; y(1) = yINI; ydot = yINI;
N= (b-a)/h;
for i=1:N
t(i+1)=t(i) + h;
y(i+1)=y(i) + ODE1(t(i),y(i))*h;
ydot(i+1)=ydot(i) + ODE2(t(i),ydot(i))*h;
end
and now here is my scrpit file:
clc; clear all
a=0;b=8;h = [0.8 0.5 0.1];yINI = [0;0];
[t,y,ydot] = odeEULER(@dydt,@dydotdt,a,b,h,yINI)
figure(1)
plot(t,y,'LineWidth',2)
xlabel('Time(s)')
ylabel('Distance travelled(m)')
title('Displacement over time')
grid on
figure(2)
plot(t,ydot,'LineWidth',2)
xlabel('Time(s)')
ylabel('Velocity (m/s)')
title('Velocity vs Time')
grid on
function dydx=dydt(t,y,ydot)
dydx=ydot;
end
function dydx=dydotdt(t,y,ydot)
g=32.2,w= 3000-800*t;T = 8000;D =((0.005*g)*(ydot^2));
dydx=((g/w)*(T-w-D));
end
Please let me know what I am to
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!