You are on page 1of 3

Vector

function kelili(p0,p1,label)
%WELCOME to my project
%this function of script for draw the vector arrow in 2D & 3D,
this skrip is free copyright, but please include the source from
which you obtain it.
%Created By: ADE JUNAIDI STC (1300022010)
% Example:
% 3D vector
% p0 = [1 2 3]; % Coordinate of the first point p0
% p1 = [4 5 6]; % Coordinate of the second point p1
% vector(p0,p1,'label')
%
% 2D vector
% p0 = [1 2]; % Coordinate of the first point p0
% p1 = [4 5]; % Coordinate of the second point p1
% vector(p0,p1,'label')

if max(size('p0'))==3
if max(size(p1))==3
x1 = p0(1);
y1 = p0(2);
z1 = p0(3);% Coordinate of the first point p0

x2 = p1(1);
y2 = p1(2);
z2 = p1(3);% Coordinate of the second point p1

%Coordinate of vector label = coordinate p0+p1/2


xl=(p1(1)+p0(1))/2;
yl=(p1(2)+p0(2))/2;
zl=(p1(3)+p0(3))/2;

% Draw a line 3D vector


quiver3( x1,y1,z1,x2-x1,y2-y1,z2-z1,0 )
text(xl, yl, zl,label); %add label in 3d vector

grid on
xlabel('x')
ylabel('y')
zlabel('z')
hold on
else
error('p0 and p1 must have the same dimension.......
Please Clear and Try again')
end
elseif max(size(p0))==2
if max(size(p1))==2
x1 = p0(1);
y1 = p0(2); % coordinate of the first point

x2 = p1(1);
y2 = p1(2);% coordinate of the second point

xl=(p1(1)+p0(1))/2;
yl=(p1(2)+p0(2))/2;

quiver( x1,y1,x2-x1,y2-y1,0 ) % Draw a line 2D


vector
text(xl, yl, label); %add label in 2d vector
grid on
xlabel('x')
ylabel('y')
hold on
else
error('p0 and p1 must have the same dimension....
Please Clear and Try Again')
end
else
error('this function only accepts 2D or 3D vector, p0 and
p1 no more than 3 dimensions..... Please check your dimensions')
end
Parabola
% input artinya membuat v0 (kecepatan awal) dan a (sudut
elevasi)

%sebagai variable yang dapat diubah-uban nantinya


v0 = input('kecepatan awal:');
a = input('sudut elevasi:');
%pendefinisian variable
h= 0.05;
a=a*pi/180;
g=9.8; %Percepatan dalam gravitas m/s^2
xmax=v0^2*sin(2*a)/g;
ymax=v0^2*sin(a)^2/(2*g);
td=2*v0*sin(a)/g; %Waktu total
x1=0;
y1=0;
for t=0:h:td+h
x=v0*t*cos(a); %jarak dalam sumbu x
y=v0*t*sin(a)-g*t^2/2; %Jarak dalam sumbu y
plot (x,y,'ro')
hold all
xlim([0 1.1*xmax]);
ylim([0 1.1*ymax]);
title('Gerak Parabola');
xlabel('Jarak (meter)');
ylabel('Ketinggian (meter)');
getframe;
x1=x1+h*v0*cos(a); %Metode Euler untuk sumbu x

y1=y1+h*(v0*sin(a)-g*t); %Metode Euler untuk sumbu y


end

You might also like