Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
function [vx , vy] = initVelocity(initialAngle, speedinitialSpeed)
	vx = cosd(initialAngle)*speedinitialSpeed;
	vy = sind(initialAngle)*speedinitialSpeed;
end

b)

Code Block
function [x, y] = position(x,y, vx, vy, dt)
	x = x + vx*dt;
	y = y + vy*dt;
end 

...

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 

...