%======================================================
%Program
Berikut adalah modifikasi dari
%Program
Metode Beda Hingga pada modul Persamaan Differensial Numerik
%Original
Author: Prof. Dr. Agus Suryanto, M.Sc.
%======================================================
%Diketahui
Masalah Kondisi Batas
%X"(t)=2*t/(1+t^2)X'(t)-2/(1+t^2)X(t)+1
%X(0)=1.25;
X(1)=-0.95
%======================================================
clear all;clc;
h=input('masukkan
h=');
N=(1-0)/h;
A=zeros(N+1,N+1);
X=zeros(N+1,1);
salah=0;
t=0:h:1;
A(1,1)=1;
A(N+1,N+1)=1;
for
i=2:N;
p=1+t(i)^2;
m=h^2;
A(i,i-1)=1+(h*t(i)/p);%a(i)
A(i,i)=(2*m/p)-2; %b(i)
A(i,i+1)=1-h*t(i)/p; %c(i)
end
F=1.25; %nilai
awal
k=((1/m)+((t(i))/(h*p)));
l=((1/m)-((2*t(i))/p));
for
i=1:N-1
if
i==1
F=[F 1-k*1.25];
elseif
i==N-1
F=[F
1+l*0.95];
else
F=[F
1];
end
end
F=[F -0.95];
B=inv(A/h^2);
X=B*transpose(F);
%penyelesaian
eksak
for
i=1:N+1
y(i)=t(i)*(1/20-1/2*pi)-9/4*t(i)^2+5/4+2*t(i)*atan(t(i))+1/2*...
log(t(i)^2+1)*t(i)^2-1/2*log(t(i)^2+1);
end
for
i=1:N+1
eror(i)=abs(y(i)-X(i));
salah=salah+eror(i);
end
fprintf('____________________________________________________________\n');
fprintf('Iterasi Nilai t(i) Nilai X(i)\n');
fprintf('-----------------------------------------------------------\n');
for
i=1:N+1;
fprintf('%f %f %f\n ',i,t(i),X(i));
end
figure(1)
plot(t,X,'ro');
grid on;
hold on;
plot(t,y,'b*');
Mas Adib saya mau sharing mengenai metode beda hingga pada matlab, boleh minta alamat emailnya
BalasHapusmaaf baru balas, silakan email ke adibjdp@gmail.com
HapusTerimakasih atas kunjungannya