Berikut ini adalah contoh studi kasus menggunakan Metoda Euler dengan menggunakan Matlab :
Studi Kasus:
Studi Kasus:
Interpolasi
Linear
Metode Euler :
Kasus : dy/dx=4x=5
Nilai awal (x0,y0) : 0 0
Artinya x0 = 0 dan y0 = 0
Nilai akhir (x)40
Artinya akan dihitung solusi persamaan diferensial saat
x=440 atau y(40)
Jumlah pita : 100
Antara x0 dan x akan dibagi 100 segmen atau pita
Hasil : 3434
Solusi persamaa diferensial y(40)=3434
Metode
Euler
function varargout =
metoda_euler(varargin)
% METODA_EULER MATLAB code for metoda_euler.fig
% METODA_EULER,
by itself, creates a new METODA_EULER or raises the existing
% singleton*.
%
% H =
METODA_EULER returns the handle to a new METODA_EULER or the handle to
% the existing
singleton*.
%
%
METODA_EULER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named
CALLBACK in METODA_EULER.M with the given input arguments.
%
%
METODA_EULER('Property','Value',...) creates a new METODA_EULER or
raises the
% existing
singleton*. Starting from the left,
property value pairs are
% applied to the
GUI before metoda_euler_OpeningFcn gets called.
An
% unrecognized
property name or invalid value makes property application
% stop. All inputs are passed to
metoda_euler_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
metoda_euler
% Last Modified by GUIDE v2.5 18-May-2018 14:20:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @metoda_euler_OpeningFcn, ...
'gui_OutputFcn', @metoda_euler_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 metoda_euler is made visible.
function
metoda_euler_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 metoda_euler (see VARARGIN)
% Choose default command line output for metoda_euler
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes metoda_euler wait for user response (see
UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command
line.
function varargout =
metoda_euler_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;
% --- Executes on button press in show_grap_pushbutton.
function show_grap_pushbutton_Callback(hObject,
eventdata, handles)
% hObject handle to
show_grap_pushbutton (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);
handles.x=0:0.1:100
handles.y=4*handles.x+5;
plot(handles.x,handles.y);
title('Pers.Diff dy/dx = 4x+5');
xlabel('x');
ylabel('y');
guidata(hObject,handles);
function
nilai_awal_x0_edit_Callback(hObject, eventdata, handles)
% hObject handle to
nilai_awal_x0_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
nilai_awal_x0_edit as text
% str2double(get(hObject,'String'))
returns contents of nilai_awal_x0_edit as a double
% --- Executes during object creation, after setting all
properties.
function
nilai_awal_x0_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to
nilai_awal_x0_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
nilai_awal_y0_edit_Callback(hObject, eventdata, handles)
% hObject handle to
nilai_awal_y0_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
nilai_awal_y0_edit as text
%
str2double(get(hObject,'String')) returns contents of nilai_awal_y0_edit
as a double
% --- Executes during object creation, after setting all
properties.
function
nilai_awal_y0_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to
nilai_awal_y0_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
nilai_akhir_edit_Callback(hObject, eventdata, handles)
% hObject handle to
nilai_akhir_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
nilai_akhir_edit as text
%
str2double(get(hObject,'String')) returns contents of nilai_akhir_edit
as a double
% --- Executes during object creation, after setting all
properties.
function
nilai_akhir_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to
nilai_akhir_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
jml_pita_edit_Callback(hObject, eventdata, handles)
% hObject handle to
jml_pita_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
jml_pita_edit as text
%
str2double(get(hObject,'String')) returns contents of jml_pita_edit as a
double
% --- Executes during object creation, after setting all
properties.
function
jml_pita_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to
jml_pita_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
hasil_euler_edit_Callback(hObject, eventdata, handles)
% hObject handle to
hasil_euler_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
hasil_euler_edit as text
%
str2double(get(hObject,'String')) returns contents of hasil_euler_edit
as a double
% --- Executes during object creation, after setting all
properties.
function
hasil_euler_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to
hasil_euler_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_euler_pushbutton.
function
calculate_euler_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to
calculate_euler_pushbutton (see GCBO)
% eventdata reserved
- to be defined in a future version of MATLAB
% handles structure
with handles and user data (see GUIDATA)
x1 = str2num(get(handles.nilai_awal_x0_edit,'String'));
y1 = str2num(get(handles.nilai_awal_y0_edit,'String'));
x2 = str2num(get(handles.nilai_akhir_edit,'String'));
pita = str2num(get(handles.jml_pita_edit,'String'));
n=0;
delt=100;
eps=1e-3;
while (abs(delt)>eps) %iterasi selama delt lebih besar dari eps
n=n+1;
%pita=pow(2,n);
%2^n
delx=(x2-x1)/pita;
x=x1;
y=y1;
while (x<x2) %Pers.Differensial yang dicari solusinya %*************************
%fx=y;
fx=4*x+5;
%fx=4;
%*************************
y=y+fx*delx; %iterasi Euler orde-1
x=x+delx;
end
if (n>1)
delt=y-y2;
end
y2=y;
end
set(handles.hasil_euler_edit,'String',num2str(y));
Lebih lengkap kamu bisa download file metode
Tidak ada komentar:
Posting Komentar