SELAMAT DATANG

matlab 16 06

 
 EULER
function pd = feuler(string_f, a, b, y0,n)
f=inline (string_f)
x(1)=a;
y(1)=y0;
h=(b-a)/n;
for i=1:n+1;
fprintf('%2g %7.4f %7.4f\n', i-1, x(i), y(i))
y(i+1)=y(i)+h*f(x(i), y(i));
x(i+1)=x(i)+h;
end
pd = y(n+1);
  
 
rungekutta
function pd = frungekutta(string_f, a, b, y0,n)
f=inline (string_f)
x(1)=a;
y(1)=y0;
h=(b-a)/n;
for i=1:n+1;
fprintf('%2g %7.4f %7.4f\n', i-1, x(i), y(i))
k1=f(x(i),y(i));
k2=f(x(i)+(1/2)*h, y(i)*(1/2)*h);
k3=f(x(i)+h, y(i)-k1*h+2*h*k2);
y(i+1)=y(i)+(1/6)*h*(k1+4*k2+k3);
x(i+1)=x(i)+h;
end
pd = y(n+1);
 
 RALSTON
function pd = fralston(string_f, a, b, y0,n)
f=inline (string_f)
x(1)=a;
y(1)=y0;
h=(b-a)/n;
for i=1:n+1;
fprintf('%2g %7.4f %7.4f\n', i-1, x(i), y(i))
k1=f(x(i),y(i));
k2=f(x(i)+h*(3/4), y(i)+k1*h*(3/4));
y(i+1)=y(i)+h*(k1+2*k2)/3;
x(i+1)=x(i)+h;
end
pd = y(n+1);
 
 panggil dengan "x^2*y" 0, 1, 1, 20.

0 komentar:

Posting Komentar

Flag Counter