# Need help writing a simple pseudo code for the following script

2 views (last 30 days)
Samuel Walker on 21 Mar 2021
Commented: John D'Errico on 21 Mar 2021
dt = 0.1;
omega1 = 10;
domega_dt = 1/1000;
R = 0.11;
S = pi*R^2;
rho = 1.225;
m = 0.43;
t=0:dt:2;
u=zeros(length(t));
v=zeros(length(t));
x=zeros(length(t));
y=zeros(length(t));
u(1) = 25;
for i = 2:length(t)
omega = omega1 - domega_dt* t(i);
vspin = omega*R;
speed = sqrt(u(i-1)^2+v(i-1)^2);
CL = 1/(2+(speed/vspin));
CD = 0.55 + 1/(22.5 + 4.2*(speed/vspin)^2.5)^0.4;
Lift = 0.5*rho*S*speed^2*CL;
Drag = 0.5*rho*S*speed^2*CD;
u(i) = u(i-1) + (dt/m)*(-Drag * u(i-1) - Lift*v(i-1))/max(speed,1e-16);
v(i) = v(i-1) + (dt/m)*(-Drag * v(i-1) + Lift*u(i-1))/max(speed,1e-16);
x(i) = x(i-1) + dt*(u(i-1)+u(i))/2;
y(i) = y(i-1) + dt*(v(i-1)+v(i))/2;
end
##### 2 CommentsShowHide 1 older comment
John D'Errico on 21 Mar 2021
Start with the first line. Think out what it does, and then think bout what it does in context of what the overall code should be used for. After all, it is you who apparently needs to use this code. So you probably have some clue what it SHOULD do. But just a list of lines of undocumented code is often worth no more than something produced by a chimp pecking away at a typewriter.