a)
Code Block |
---|
function [vx , vy] = initVelocity(initialAngle, speedinitialSpeed) vx = coscosd(initialAngle)*speedinitialSpeed; vy = sinsind(initialAngle)*speedinitialSpeed; end |
b)
Code Block |
---|
function [x, y] = position(x,y, vx, vy, dt) x = x + vx*dt; y = y + vy*dt; end |
c)
Code Block |
---|
function [ ax , ay ] = acceleration (vx ,vy) k = 0.01; g = 9.81; ax = -k*vx*abs(vx); ay = -k*vy*abs(vy)-g; end |
d)
Code Block |
---|
function [vx , vy] = velocity(ax, ay, vx, vy, dt) vx = vx + ax * dt; vy = vy + ay * dt; end |
e)
Code Block |
---|
function [xv x, yvy] = trajectory(initialSpeed, initialAngle, height) dt =0.01; xxPos = 0; % Nåværende verdi for x yyPos = height ; % Nåværende verdi for y [vx , vy] = initVelocity(initialAngle ,initialSpeed); i = 1; while yyPos > 0 % kalkuler akselerasjon [ax , ay] = acceleration(vx, vy); % kalkuler fart [vx , vy] = velocity(ax, ay, vx, vy, dt); % kalkuler endring i distanse [xxPos, yyPos] = position (xxPos, yyPos, vx, vy, dt); xvx(i) = xxPos; yvy(i) = yyPos; i = i + 1; end end |
f)
Code Block |
---|
|
function plotTrajectory(initialSpeed, initialAngle, height)
[x, y] = trajectory(initialSpeed, initialAngle, height);
plot (x, y);
grid on;
xlabel('x');
ylabel('y');
title('plotTrajectory');
end |
g)
Code Block |
---|
function plotTrajectoryLength (initialSpeed, start, step, stop, height)
initialAngles = start:step:stop;
n = length(initialAngles);
lengths = zeros(n,1);
for i = 1:n
[x, y] = trajectory(initialSpeed, initialAngles(i), height);
j = length (x);
lengths (i) = x(j);
end
plot (initialAngles ,lengths);
xlabel('Angle');
ylabel('y');
grid on;
title('plotTrajectoryLength');
end |
Det kan virke som om pi/4 (45 grader) gir lengst støt. Dette virker intuitivt korrekt.
Jo høyere man kaster fra, jo bedre er det å kaste mest mulig rett frem (i x-retning).