Forward euler - a system of 4 ode
Show older comments
I am trying to program in matlab a code to excute forward euler. I have these DE:
x'(t)=u
y'(t)=v
u'(t)=-kx*u*V
v'(t)=-g-ky(v*V)
where kx,ky and g are constants and V=sqrt(u^2+v^2)
The first thing that I have done is that I have called:
w_1'=x'
w_2'=y'
w_3'=u'
w_4'=v'
so I can express the 4 system of DE in terms of w:
w_3
w_4
-kx*w_3+sqrt((w_3)^2+(w_4)^2)
-g-ky*w_4*(sqrt((w_3)^2+(w_4)^2)
Now to the MATLAB code:
x0 = 0;
N = 16000;
h = 2./N;
kx=0.020;
ky=0.065;
g=9.81;
x_i = [0 ; 1.5; 19*cos(45); 19*sin(45)]; % initialconditons
for i = 1:N;
x_n = x0 + (i-1).*h;
diff=[x_n;x_n;-kx*(x_n*sqrt((x_n).^2+(x_n).^2));-g-ky*x_n*sqrt((x_n).^2+(x_n).^2)];
e= x_i + h.*diff; %euluerforward
end
I am not sure if I have done it right, because my answers are almost similiar to my initialconditions?
Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!