# Implement friction into a model, related to the velocity. (Missile Launch)

11 views (last 30 days)
The Legend on 25 Jan 2020
Edited: Jim Riggs on 26 Jan 2020
Does anyone know how I could implement friction into my code located down below?
The friction should be defined as: Ff_vector = - gamma * | v_vector | * v_vector, and should be substracted from the different velocity components of the missile.
The current distance and time outputs I get from running my code are (without friction implemented): Also important to note is that there is no thrust, just a starting velocity of 2000 m/s.
The rocket also has a mass now of 500 kg.
clear;
close all;
clc;
tic
tic
aT = 0;
format long
for i = [37:2:53]
r = 6371 * 10^3;
G = 6.674 * 10^-11;
M = 5.972 * 10^24;
g = (G * M)/(r^2);
theta0 = i;
ax = 0;
ay = r;
v0 = 2000;
vx0 = v0*cosd(theta0);
vy0 = v0*sind(theta0);
x = 0;
y = r;
vx = vx0;
vy = vy0;
T = 0;
dt = 0.01;
at = 0;
landed = 0;
z = 1;
while landed == 0
z = z + 1;
T = T + dt;
xo = x;
yo = y;
x = x + vx * dt;
y = y + vy * dt;
d = sqrt(x^2 + y^2);
alpha = atand(x/y);
g = (G*M)/(d^2);
gy = cosd(alpha) * g;
gx = sind(alpha) * g;
vy = vy - (gy * dt);
vx = vx - (gx * dt);
v = vx/sin(alpha);
ax = [ax, x];
ay = [ay, y];
if d < r
landed = 1;
end
end
aT = [aT, T]; % This is the list of times it took for each missile to land
distance = (alpha/360) * 2 * pi * r;
ad = [ad, distance]; % This is the list of distances each missile travelled
figure(1)
th = 2.8*pi/6:pi/500:3.1*pi/6;
xunit = r * cos(th) + 0;
yunit = r * sin(th) + 0;
figure(2)
hold on
plot(ax, ay)
toc
end
th = 2.8*pi/6:pi/500:3.1*pi/6;
xunit = r * cos(th) + 0;
yunit = r * sin(th) + 0;
plot(xunit, yunit)
hold off
legend('37 degrees', '39 degrees', '41 degrees', '43 degrees', '45 degrees', '47 degrees', '49 degrees', '51 degrees', '53 degrees', 'earth')
title('The trajectory of the different missiles')
xlabel('x(m)')
ylabel('y(m)')
toc
The desired output, with friction included should be: Any help is immensly appreciated!

The Legend on 25 Jan 2020
bump
Walter Roberson on 25 Jan 2020
should be substracted from the different velocity components of the missile.
Would that be before or after
x = x + vx * dt;
y = y + vy * dt;
? Are you calculating the friction coefficients before moving, or are you calculating them after moving ?
The Legend on 26 Jan 2020
After the missile is launched with initial velocity 2000 m/s

Jim Riggs on 26 Jan 2020
This question is familiar.
look here.

The Legend on 26 Jan 2020
This unfortunately did not help, I am unable to get the distance values that I should get, thank's for the help.
Jim Riggs on 26 Jan 2020
Assuming that the code gives you the correct answer without the friction term, to add friction do the following;
change this:
vy = vy - gy * dt;
vx = vx - gx * dt;
to this:
Vtot = sqrt(vx^2 + vy^2);
Fy = -gamma * Vtot * vy;
Fx = -gamma * Vtot * vx;
vy = vy + dt*(Fy/mass - gy);
vx = vx + dt*(Fx/mass - gx);
mass is 500 kg.
EDIT: after some thought, it ocurrs to me that the 1/mass factor could be included in gamma. There is no way for me to know. If this is the case, then omit the division by mass "/mass"