Mungkin mudah mencontohkan gerak para bola kepada siswa. Guru cukup menunjukkan bagaimana bola ditendang melambung, pasti membentuk gerak para bola. Namun, apakah guru akan bisa menunjukkan bagaimana gerak parabola disimulasikan secara persekian detik dapat menggambarkan gerakkan parabola sebuh bola. Salah, satu yang girunakan untuk mensimulasikan gerak parabola adalah dengan Matlab. Keunggulan dari Matlab selain dapat menunjukkan gerakan per detik, juga dapat diinteraksikan sesai dengan persamaan parabola.

Untuk membuat simulasi dengan Matlab, kita dapat menggunakan program dari Guide Matlab. Program ini dapat didesain dengan kehendak kita baik dengan input, dengan slider, dengan button, dan seterusnya. Kali ini kita akan mendesain metode input dan menayangkan grafik. Langkah-langkahnya sebagai berikut.

1. Buatlah desain dengan metode GUI sesebagai berikut

2. Lalu ubungkan tiap tombol dengen crip seperti di bawah ini

function varargout = inputgerakpeluru(varargin)
% INPUTGERAKPELURU MATLAB code for inputgerakpeluru.fig
% INPUTGERAKPELURU, by itself, creates a new INPUTGERAKPELURU or raises the existing
% singleton*.
%
% H = INPUTGERAKPELURU returns the handle to a new INPUTGERAKPELURU or the handle to
% the existing singleton*.
%
% INPUTGERAKPELURU(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in INPUTGERAKPELURU.M with the given input arguments.
%
% INPUTGERAKPELURU(‘Property’,’Value’,…) creates a new INPUTGERAKPELURU or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before inputgerakpeluru_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to inputgerakpeluru_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE’s Tools menu. Choose “GUI allows only one
% instance to run (singleton)”.
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help inputgerakpeluru

% Last Modified by GUIDE v2.5 08-Dec-2017 10:27:41

% Begin initialization code – DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @inputgerakpeluru_OpeningFcn, …
‘gui_OutputFcn’, @inputgerakpeluru_OutputFcn, …
‘gui_LayoutFcn’, [] , …
‘gui_Callback’, []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code – DO NOT EDIT

% — Executes just before inputgerakpeluru is made visible.
function inputgerakpeluru_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to inputgerakpeluru (see VARARGIN)

% Choose default command line output for inputgerakpeluru
handles.output = hObject;
set(hObject,’toolbar’,’figure’);
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes inputgerakpeluru wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% — Outputs from this function are returned to the command line.
function varargout = inputgerakpeluru_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

function v_edit_Callback(hObject, eventdata, handles)
% hObject handle to v_edit (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
input = str2num(get(hObject,’String’))
if(isempty(input))
set(hObject,’String’,’0′)
end
guidata(hObject, handles);
% Hints: get(hObject,’String’) returns contents of v_edit as text
% str2double(get(hObject,’String’)) returns contents of v_edit as a double

% — Executes during object creation, after setting all properties.
function v_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to v_edit (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles empty – handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))
set(hObject,’BackgroundColor’,’white’);
end

function alfa_edit_Callback(hObject, eventdata, handles)
% hObject handle to alfa_edit (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
input = str2num(get(hObject,’String’))
if(isempty(input))
set(hObject,’String’,’0′)
end
guidata(hObject, handles);
% Hints: get(hObject,’String’) returns contents of alfa_edit as text
% str2double(get(hObject,’String’)) returns contents of alfa_edit as a double

% — Executes during object creation, after setting all properties.
function alfa_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to alfa_edit (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles empty – handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))
set(hObject,’BackgroundColor’,’white’);
end

% — Executes on button press in Playpushbutton.
function Playpushbutton_Callback(hObject, eventdata, handles)
% hObject handle to Playpushbutton (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1)
%mendapatkan nilai dari input
d= get(handles.v_edit,’String’)
e= get(handles.alfa_edit,’String’)
f=get(handles.h_edit,’String’)
v0=str2num(d);
a= str2num(e);
%pendefinisian variable
h= 0.04;
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=str2num(f);
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
guidata(hObject, handles); %updates the handles

% — Executes on button press in puclearshbutton.
function puclearshbutton_Callback(hObject, eventdata, handles)
% hObject handle to puclearshbutton (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cla(handles.axes1,’reset’)
guidata(hObject, handles)

function h_edit_Callback(hObject, eventdata, handles)
% hObject handle to h_edit (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
input = str2num(get(hObject,’String’))
if(isempty(input))
set(hObject,’String’,’0′)
end
guidata(hObject, handles);
% Hints: get(hObject,’String’) returns contents of h_edit as text
% str2double(get(hObject,’String’)) returns contents of h_edit as a double

% — Executes during object creation, after setting all properties.
function h_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to h_edit (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles empty – handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))
set(hObject,’BackgroundColor’,’white’);
end

3. Menjalankannya

Secara lebih jelas, Anda dapat melihat video berikut