0% found this document useful (0 votes)
18 views

Script All

This document contains MATLAB code for two GUI applications: 1) TUGASWINE is a GUI with editable text boxes and a plot that allows modeling of exponential decay and impulse functions based on user input. 2) PEMODELANTITISSEAJASMINE is a GUI for modeling titis (mastitis) in sea goats, with callbacks and functions to open and close the GUI.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Script All

This document contains MATLAB code for two GUI applications: 1) TUGASWINE is a GUI with editable text boxes and a plot that allows modeling of exponential decay and impulse functions based on user input. 2) PEMODELANTITISSEAJASMINE is a GUI for modeling titis (mastitis) in sea goats, with callbacks and functions to open and close the GUI.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

TUGAS 1

function varargout = tugaswine(varargin)


% TUGASWINE MATLAB code for tugaswine.fig
% TUGASWINE, by itself, creates a new TUGASWINE or raises the existing
% singleton*.
%
% H = TUGASWINE returns the handle to a new TUGASWINE or the handle to
% the existing singleton*.
%
% TUGASWINE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TUGASWINE.M with the given input
arguments.
%
% TUGASWINE('Property','Value',...) creates a new TUGASWINE or raises
the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before tugaswine_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to tugaswine_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 tugaswine

% Last Modified by GUIDE v2.5 13-Mar-2018 18:58:08

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tugaswine_OpeningFcn, ...
'gui_OutputFcn', @tugaswine_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 tugaswine is made visible.


function tugaswine_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 tugaswine (see VARARGIN)
% Choose default command line output for tugaswine
handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes tugaswine wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = tugaswine_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 edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text


% str2double(get(hObject,'String')) returns contents of edit1 as a
double

% --- Executes during object creation, after setting all properties.


function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text


% str2double(get(hObject,'String')) returns contents of edit2 as a
double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text


% str2double(get(hObject,'String')) returns contents of edit3 as a
double

% --- Executes during object creation, after setting all properties.


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text


% str2double(get(hObject,'String')) returns contents of edit4 as a
double

% --- Executes during object creation, after setting all properties.


function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cawal = str2double(get(handles.edit1, 'String'));
konstanta = str2double(get(handles.edit2, 'String'));
alpha = str2double(get(handles.edit3, 'String'));
waktu = str2double(get(handles.edit4, 'String'));

EX(1)=cawal;
IMP(1)=cawal;
for i = 2:waktu;
t(i)=i-1;
T = (t(i))-(t(i-1));

%rumus
EX(i)=(1-(T*konstanta))*EX(i-1);
IMP(i)=IMP(i-1)/(1+T*konstanta);

%tabel
myform = guidata (gcbo);
data(i,1)=t(i);
data(i,2)=EX(i);
data(i,3)=IMP(i);

end

plot (t,EX,'-.mo');
hold on;
plot (t,IMP,'-.rs');
hold on;
grid on

set(myform.uitable1,'data',data);

TUGAS 2
function varargout = pemodelanTitisSeaJasmine(varargin)
% PEMODELANTITISSEAJASMINE MATLAB code for pemodelanTitisSeaJasmine.fig
% PEMODELANTITISSEAJASMINE, by itself, creates a new
PEMODELANTITISSEAJASMINE or raises the existing
% singleton*.
%
% H = PEMODELANTITISSEAJASMINE returns the handle to a new
PEMODELANTITISSEAJASMINE or the handle to
% the existing singleton*.
%
% PEMODELANTITISSEAJASMINE('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in PEMODELANTITISSEAJASMINE.M with the given
input arguments.
%
% PEMODELANTITISSEAJASMINE('Property','Value',...) creates a new
PEMODELANTITISSEAJASMINE or raises the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before pemodelanTitisSeaJasmine_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to pemodelanTitisSeaJasmine_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


pemodelanTitisSeaJasmine

% Last Modified by GUIDE v2.5 24-Mar-2018 19:16:57

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pemodelanTitisSeaJasmine_OpeningFcn,
...
'gui_OutputFcn', @pemodelanTitisSeaJasmine_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 pemodelanTitisSeaJasmine is made visible.


function pemodelanTitisSeaJasmine_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 pemodelanTitisSeaJasmine (see
VARARGIN)

% Choose default command line output for pemodelanTitisSeaJasmine


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes pemodelanTitisSeaJasmine wait for user response (see


UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = pemodelanTitisSeaJasmine_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 waktu_Callback(hObject, eventdata, handles)


% hObject handle to waktu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of waktu as text


% str2double(get(hObject,'String')) returns contents of waktu as a
double

% --- Executes during object creation, after setting all properties.


function waktu_CreateFcn(hObject, eventdata, handles)
% hObject handle to waktu (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 kons_Callback(hObject, eventdata, handles)


% hObject handle to kons (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of kons as text


% str2double(get(hObject,'String')) returns contents of kons as a
double

% --- Executes during object creation, after setting all properties.


function kons_CreateFcn(hObject, eventdata, handles)
% hObject handle to kons (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 koef_Callback(hObject, eventdata, handles)


% hObject handle to koef (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of koef as text


% str2double(get(hObject,'String')) returns contents of koef as a
double

% --- Executes during object creation, after setting all properties.


function koef_CreateFcn(hObject, eventdata, handles)
% hObject handle to koef (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 pushbutton3.


function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

hold off

koefisien = str2double(get(handles.koef, 'String'));


konstanta = str2double(get(handles.kons, 'String'));
wkt = str2double(get(handles.waktu, 'String'));
alfa = str2double(get(handles.alf, 'String'));

finite(1)=koefisien;
explicit(1)=koefisien;
implicit(1)=koefisien;
hybrid(1)=koefisien;
analytical(1)=koefisien;

data(1,1)=0;
data(1,2)=finite(1);
data(1,3)=explicit(1);
data(1,4)=implicit(1);
data(1,5)=hybrid(1);
data(1,6)=analytical(1);

for w = 2:wkt;
t(w)=w-1;
deltaT = (t(w))-(t(w-1));

%rumus
finite(w)=((-konstanta)*(finite(w-1))*deltaT+(finite(w-1)));
explicit(w)=(1-(deltaT*konstanta))*explicit(w-1);
implicit(w)=implicit(w-1)/(1+deltaT*konstanta);
hybrid(w)=((explicit(w)*alfa)+((implicit(w))*(1-alfa)));
analytical(w)=((koefisien)*(exp((-konstanta)*(t(w)))));

%tabel
myform = guidata (gcbo);
data(w,1)=t(w);
data(w,2)=finite(w);
data(w,3)=explicit(w);
data(w,4)=implicit(w);
data(w,5)=hybrid(w);
data(w,6)=analytical(w);

end
plot (t,finite,'--go');
hold on;
plot (t,explicit,'-.cs');
hold on;
plot (t,implicit,'--mp');
hold on;
plot (t,hybrid,'-.r*');
hold on;
plot (t,analytical,'--b');
hold on;
legend('Finite' , 'Explicit' , 'Implicit', 'Hybrid', 'Analytical',
'Location', 'West');
grid on

set(myform.uitable1,'data',data);

% --- Executes on button press in Exit.


function Exit_Callback(hObject, eventdata, handles)
% hObject handle to Exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;

function alf_Callback(hObject, eventdata, handles)


% hObject handle to alf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of alf as text


% str2double(get(hObject,'String')) returns contents of alf as a
double

% --- Executes during object creation, after setting all properties.


function alf_CreateFcn(hObject, eventdata, handles)
% hObject handle to alf (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

TUGAS 3
rhosea=1025;
rhosea2=1026;
rho=1025.5;
g=9.81;
R=0.0025;
z0=-75;
ntot=1800;
wobj(1)=0;
zobj(1)=z0;
bf = -g*(rho-rhosea2)/rho;

for i=2:ntot;
t(i)=i-1;
dt=(t(i))-(t(i-1));

wobj(i) = (wobj(i-1)+dt*bf)/(1+R*dt);
zobj (i) = zobj(i-1)+((dt)*wobj(i-1));

if zobj (i) >-50;


bf=-g*(rho-rhosea)/rho;
else zobj(i)<-50;
bf=-g*(rho-rhosea2)/rho;

end

plot(zobj,'m');
title('Lokasi Benda Terapung Sebagai Fungsi Waktu');
xlabel('Waktu(s)');
ylabel('Kedalaman(m)');

hold on

end

TUGAS 4
Ampl = 2.0; %amplitudo
gelombang
g = 9.81; %grafitasi
h = 5; %kedalaman
T = 10; %periode gelombang
c = (g*h)^(1/2); % fase kecepatan
lmd = T*c;
u0 = Ampl*((g/h)^(1/2)); %amplitudo U

xrange = 2*lmd;
x=[0:xrange/h:xrange];
t = 10;
trange = 2*T;
dt = trange/100;
ntot=trange/dt;

%inisial gelombang awal


xpos1 = x; zpos1(1:h+1) = 1;
xpos2 = x; zpos2(1:h+1) = 3;
xpos3 = x; zpos3(1:h+1) = 4;
xpos4 = x; zpos4(1:h+1) = 5;

for n = 2:ntot; %mulai iterasi


hold on;
clf;

Agel = Ampl*sin(2*3.14*(x/lmd-t/T));
% rumus gelombang
u = u0*sin(2*3.14*(x/lmd-t/T));
%untuk menentukan U nya
ked = ((-u0/lmd))*(cos(((2*3.14)*x/lmd)-((2*3.14)*(t/T))));
%kedalaman gelombang

%lokasi untuk setiap kedalaman


xpos1 = xpos1+dt*u; w = ked.*zpos1; zpos1 = zpos1+dt*w;
xpos2 = xpos2+dt*u; w = ked.*zpos2; zpos2 = zpos2+dt*w;
xpos3 = xpos3+dt*u; w = ked.*zpos3; zpos3 = zpos3+dt*w;
xpos4 = xpos4+dt*u; w = ked.*zpos4; zpos4 = zpos4+dt*w;

%plot grafik

plot(xpos1,-h+zpos1,'g--');
hold on;
plot(xpos2,-h+zpos2,'r--');
hold on;
plot(xpos3,-h+zpos3,'m--');
hold on;
plot(xpos4,-h+zpos4,'c--');
hold on;
plot(x,Agel,'b');

drawnow;
t = t+dt;

end

You might also like