Interpolasi adalah cara menentukan nilai yang berada di antara dua nilai diketahui berasarkan suatu fungsi persamaan. Interpolasi linear adalah cara menentukan nilai yang berada di antara dua nilai diketahui berdasarkan persamaan linear (persamaan garis lurus). Persamaan linear disebut juga dengan persamaan garis lurus karena jika hasil persamaan linear digambarkan pada kertas grafik maka bentuk kurvanya adalah garis lurus.
Berikut ini adalah contoh atau gambaran dari studi kasus Interpolasi linear menggunakan Matlab
Studi
Kasus :
Interpolasi
Linear
Masukan
x1 y1 : 1 1.5
Masukan
x2 y2 3 2.5
Masukan
koordinat titik – titik yang akan dicari interpolasinya
Masukan
x:2.1
Menentukan
nilai absis dari titik yang akan dicari interpolasinya
Hasilnya
y : 2.05
Hasil
interpolasi linear dari titik – titik tersebut adalah 2.05
Interpolasi
Linear
function varargout =
Interpolasi_Linear(varargin)
% INTERPOLASI_LINEAR MATLAB code for Interpolasi_Linear.fig
%
INTERPOLASI_LINEAR, by itself, creates a new INTERPOLASI_LINEAR or
raises the existing
% singleton*.
%
% H =
INTERPOLASI_LINEAR returns the handle to a new INTERPOLASI_LINEAR or the handle
to
% the existing
singleton*.
%
%
INTERPOLASI_LINEAR('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named
CALLBACK in INTERPOLASI_LINEAR.M with the given input arguments.
%
%
INTERPOLASI_LINEAR('Property','Value',...) creates a new
INTERPOLASI_LINEAR or raises the
% existing
singleton*. Starting from the left,
property value pairs are
% applied to the
GUI before Interpolasi_Linear_OpeningFcn gets called. An
% unrecognized
property name or invalid value makes property application
% stop. All inputs are passed to
Interpolasi_Linear_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
Interpolasi_Linear
% Last Modified by GUIDE v2.5 18-May-2018 15:01:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Interpolasi_Linear_OpeningFcn, ...
'gui_OutputFcn',
@Interpolasi_Linear_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 Interpolasi_Linear is made
visible.
function
Interpolasi_Linear_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 Interpolasi_Linear (see VARARGIN)
% Choose default command line output for Interpolasi_Linear
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Interpolasi_Linear wait for user response
(see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command
line.
function varargout =
Interpolasi_Linear_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 x1_edit_Callback(hObject,
eventdata, handles)
% hObject handle to
x1_edit (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 x1_edit
as text
%
str2double(get(hObject,'String')) returns contents of x1_edit as a
double
% --- Executes during object creation, after setting all
properties.
function x1_edit_CreateFcn(hObject,
eventdata, handles)
% hObject handle to
x1_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 x2_edit_Callback(hObject,
eventdata, handles)
% hObject handle to
x2_edit (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 x2_edit
as text
%
str2double(get(hObject,'String')) returns contents of x2_edit as a
double
% --- Executes during object creation, after setting all
properties.
function x2_edit_CreateFcn(hObject,
eventdata, handles)
% hObject handle to
x2_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 y1_edit_Callback(hObject,
eventdata, handles)
% hObject handle to
y1_edit (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 y1_edit
as text
%
str2double(get(hObject,'String')) returns contents of y1_edit as a
double
% --- Executes during object creation, after setting all
properties.
function y1_edit_CreateFcn(hObject,
eventdata, handles)
% hObject handle to
y1_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 y2_edit_Callback(hObject,
eventdata, handles)
% hObject handle to
y2_edit (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 y2_edit
as text
%
str2double(get(hObject,'String')) returns contents of y2_edit as a
double
% --- Executes during object creation, after setting all properties.
function y2_edit_CreateFcn(hObject,
eventdata, handles)
% hObject handle to
y2_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 x_edit_Callback(hObject,
eventdata, handles)
% hObject handle to
x_edit (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 x_edit as
text
%
str2double(get(hObject,'String')) returns contents of x_edit as a double
% --- Executes during object creation, after setting all
properties.
function x_edit_CreateFcn(hObject,
eventdata, handles)
% hObject handle to
x_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 y_edit_Callback(hObject,
eventdata, handles)
% hObject handle to
y_edit (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 y_edit as
text
%
str2double(get(hObject,'String')) returns contents of y_edit as a double
% --- Executes during object creation, after setting all
properties.
function y_edit_CreateFcn(hObject,
eventdata, handles)
% hObject handle to
y_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 calculate_pushbutton.
function
calculate_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to
calculate_pushbutton (see GCBO)
% eventdata reserved
- to be defined in a future version of MATLAB
% handles structure
with handles and user data (see GUIDATA)
hold off;
x1 = str2num(get(handles.x1_edit,'String'));
y1 = str2num(get(handles.y1_edit,'String'));
x2 = str2num(get(handles.x2_edit,'String'));
y2 = str2num(get(handles.y2_edit,'String'));
x = str2num(get(handles.x_edit,'String'));
y=(((y2-y1)/(x2-x1))*(x-x1))+y1;
%plotting data x
x(1)=x1;
yy(1)=y1;
xx(2)=x2; yy(2)=y2;
xx(3)=x; yy(3)=y;
plot(xx,yy,'o');
hold on;
set(handles.y_edit,'String',num2str(y));
%plotting y
axes(handles.axes1); x=0:0.1:x2+1
y=(((y2-y1)/(x2-x1)).*(x-x1))+y1;
%x=0:10;
%y=x.^2;
plot(x,y);
title('y=(((y2-y1)/(x2-x1))*(x-x1))+y1');
xlabel('x');
ylabel('y');
Lebih lengkapnya file atau sourcenya kamu bisa download disini | link 1 |
Tidak ada komentar:
Posting Komentar