You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

function [vx , vy] = initVelocity(initialAngle, speed)
	vx = cos(initialAngle)*speed;
	vy = sin(initialAngle)*speed;
end
function [x, y] = position(x,y, vx, vy, dt)
	x = x + vx*dt;
	y = y + vy*dt;
end 
function [ ax , ay ] = acceleration (vx ,vy)
	k = 0.01;
	g = 9.81;
	ax = -k*vx*abs(vx);
	ay = -k*vy*abs(vy)-g;
end
function [vx , vy] = velocity(ax, ay, vx, vy, dt)
	vx = vx + ax * dt;
	vy = vy + ay * dt;
end
 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
 
 
  • No labels