How do I implement friction into my script?

1 view (last 30 days)
clear;
close all;
clc;
tic
aT = 0;
ad = 0;
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 = 3000;
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];
distance = (alpha/360) * 2 * pi * r;
ad = [ad, distance];
fprintf('Checked for degree: %.0f\n', i)
end
toc
This is a model that I've created for calculating the distance a missile travels under the following conditions:
velocity = 2000 m / s
gravity = dependent on height
distance = influenced by curvature of the earth
friction = not present
Now, I am trying to implement friction into my script and I know that the friction force is related to the speed by a coefficient:
Ff = gamma * | v | * v
With Ff and v being vectors in the direction of the missile.
Could anyone please give me a hint to what I could do to implement this relation into the script.
I will then alternate gamma and compare the results of the script to get the best value for gamma.

Accepted Answer

Thiago Henrique Gomes Lobato
Friction is a force that produces acceleration which changes the velocity, so if you add an additional term to the velocity update you may get the effect that you want to. Theoretically you would need to define the mass of the missile, but this can be controlled by the parameter gamma (both are constant, costant*constant = constant), in the end you will have something like:
gamma = 1e-5;
vy = vy - (gy * dt) - gamma*abs(vy)*vy*dt;
vx = vx - (gx * dt) - gamma*abs(vx)*vx*dt;
  3 Comments
Jim Riggs
Jim Riggs on 26 Jan 2020
Edited: Jim Riggs on 26 Jan 2020
This equation is not the correct form.
it should be
Vtot = sqrt(vx^2+vy^2);
vy = vy - dt * (gy + gamma*Vtot*vy/mass);
vx = vx - dt * (gx + gamma*Vtot*vy/mass);
the product gamma*Vtot*vx is a FORCE in the x direction.
Force/mass is an accleration in the x direction.
(although, I suppose that is is possible that the 1/mass factor is already included in gamma, so if this is the case, then the equation should be:
vy = vy - dt * (gy + gamma*Vtot*vy);
vx = vx - dt * (gx + gamma*Vtot*vx);
For more detail on the Vtot * vx factor see the discussion here
Thiago Henrique Gomes Lobato
You're right, it should be Vtot. I didn't reflect enough time at first and gave a too quick response. Thanks for coming back to clear this even though it was already in the other question.

Sign in to comment.

More Answers (0)

Categories

Find more on Aerospace Applications 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!