a)
Code Block |
---|
function [vx , vy] = initVelocity(initialAngle, speed) vx = cos(initialAngle)*speed; vy = sin(initialAngle)*speed; 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 , yv] = trajectory(initialSpeed, initialAngle, height) dt =0.01; x = 0; y = height ; [vx , vy] = initVelocity(initialAngle ,initialSpeed); i = 1; while y > 0 % kalkuler akselerasjon [ax , ay] = acceleration(vx, vy); % kalkuler fart [vx , vy] = velocity(ax, ay, vx, vy, dt); % kalkuler endring i distanse [x, y] = position (x, y, vx, vy, dt); xv(i) = x; yv(i) = y; i = i + 1; end end |
f)
Code Block |
---|
function plotTrajectory(initialSpeed, initialAngle, height) [x, y] = trajectory(initialSpeed, initialAngle, height); plot (x, y); end |
...