syms x y
fxy= -2.2067*10^-12*(y^4-81*10^8)*h;
a= 0;
b=480;
n=10;
h= (b-a)/n;
x1= a;
y1= 1200;
ys= 647.57; %nilai sebenarnya
es=1;
N=[x1 y1 es ];
for i=1:n
y2= y1+ subs (fxy,{x,y},{x1,y1});
x2= x1+h;
es= abs ((ys-y2)/ys);
N= [N;x2 y2 es ];
x1=x2;
y1=y2;
end
N
multi_simpson
Diposting oleh
Unknown
/
Comments: (0)
%multi_simpson
syms x
fx =x^2+x+2;
a = 0;
b = 2;
fy = int(fx,x);
fya = subs(fy,x,a);
fyb = subs(fy,x,b);
ha = fyb-fya
fa = subs(fx,x,a);
fb = subs(fx,x,b);
n = 4;
h = (b-a)/n;
ganjil=0;
genap = 0;
for i=1:(n-1)l
if rem (i,2)== 0
genap=genap+subs(fx,x,a+i*h)
else
ganjil=ganjil+subs(fx,x,a+i*h)
end
end
hk = h/3*(fxa+fxb+4*ganjil+2*genap)
ea = abs((ha-hk)/hs)
syms x
fx =x^2+x+2;
a = 0;
b = 2;
fy = int(fx,x);
fya = subs(fy,x,a);
fyb = subs(fy,x,b);
ha = fyb-fya
fa = subs(fx,x,a);
fb = subs(fx,x,b);
n = 4;
h = (b-a)/n;
ganjil=0;
genap = 0;
for i=1:(n-1)l
if rem (i,2)== 0
genap=genap+subs(fx,x,a+i*h)
else
ganjil=ganjil+subs(fx,x,a+i*h)
end
end
hk = h/3*(fxa+fxb+4*ganjil+2*genap)
ea = abs((ha-hk)/hs)
simpsons1/3
Diposting oleh
Unknown
/
Comments: (0)
%simpsons1/3
syms x
fx =x^2+x+2;
a = 0;
b = 2;
fy = int(fx,x);
fya = subs(fy,x,a);
fyb = subs(fy,x,b);
ha = fyb-fya
fxa = subs(fx,x,a);
fxb = subs(fx,x,b);
c = (a+b)/2;
fxc = subs(fx,x,c);
hk = (b-a)/6*(fxa+fxb+4*fxc)
ea = abs((ha-hk)/ha)
%boleh juga hk = h/3 *(fxa+fxb+4*fxc)
syms x
fx =x^2+x+2;
a = 0;
b = 2;
fy = int(fx,x);
fya = subs(fy,x,a);
fyb = subs(fy,x,b);
ha = fyb-fya
fxa = subs(fx,x,a);
fxb = subs(fx,x,b);
c = (a+b)/2;
fxc = subs(fx,x,c);
hk = (b-a)/6*(fxa+fxb+4*fxc)
ea = abs((ha-hk)/ha)
%boleh juga hk = h/3 *(fxa+fxb+4*fxc)
multi_trapezoid
Diposting oleh
Unknown
/
Comments: (0)
%multi_trapezoid
syms x
fx =x^2+x+2;
a = 0;
b = 2;
fy = int(fx,x);
fya = subs(fy,x,a);
fyb = subs(fy,x,b);
hs = fyb-fya
fxa = subs(fx,x,a);
fxb = subs(fx,x,b);
n = 100;
h = (b-a)/n;
fd = 0;
for i=1:(n-1)
c = a+i*h;
fxc = subs(fx,x,c);
fd = fd+fxc;
end
hk = h/2*(fxa+fxb+2*fd)
ea = abs((hs-hk)/hs)
syms x
fx =x^2+x+2;
a = 0;
b = 2;
fy = int(fx,x);
fya = subs(fy,x,a);
fyb = subs(fy,x,b);
hs = fyb-fya
fxa = subs(fx,x,a);
fxb = subs(fx,x,b);
n = 100;
h = (b-a)/n;
fd = 0;
for i=1:(n-1)
c = a+i*h;
fxc = subs(fx,x,c);
fd = fd+fxc;
end
hk = h/2*(fxa+fxb+2*fd)
ea = abs((hs-hk)/hs)
single_trapezoid_rule_integration
Diposting oleh
Unknown
/
Comments: (0)
%single_trapezoid_rule_integration
syms x
fx =x^2+x+2;
a = 0;
b = 2;
fy = int(fx,x);
fya = subs(fy,x,a);
fyb = subs(fy,x,b);
hs = fyb-fya
fxa = subs(fx,x,a);
fxb = subs(fx,x,b);
hk = (b-a)*(fxa+fxb)/2
ea= abs((hs-hk)/hs)
syms x
fx =x^2+x+2;
a = 0;
b = 2;
fy = int(fx,x);
fya = subs(fy,x,a);
fyb = subs(fy,x,b);
hs = fyb-fya
fxa = subs(fx,x,a);
fxb = subs(fx,x,b);
hk = (b-a)*(fxa+fxb)/2
ea= abs((hs-hk)/hs)
newton_raphson
Diposting oleh
Unknown
/
Comments: (0)
%newton_raphson
syms x % deklarasi fungsi x
fx = x^2+x-3;
%fx =x^3-0.165x^2+3.993*10^-4
fy= diff (fx,x);
x1 = -1;
fx1 = subs (fx,x,x1); % mensubtitiuskan xl ke fxl
fy1 = subs (fy,x,x1);
x2 = x1-(fx1/fy1);
ea = abs (x2-x1)/x2;
N = [x1 x2 ea];
x1=x2;
es = 0.0001;
n= 100;
for i = 2:n
fx1 = subs (fx,x,x1); % mensubtitiuskan xl ke fxl
fy1 = subs (fy,x,x1);
x2 = x1-(fx1/fy1);
ea = abs (x2-x1)/x2;
N = [N;x1 x2 ea];
x1=x2;
if ea<es
break
end
end
N
syms x % deklarasi fungsi x
fx = x^2+x-3;
%fx =x^3-0.165x^2+3.993*10^-4
fy= diff (fx,x);
x1 = -1;
fx1 = subs (fx,x,x1); % mensubtitiuskan xl ke fxl
fy1 = subs (fy,x,x1);
x2 = x1-(fx1/fy1);
ea = abs (x2-x1)/x2;
N = [x1 x2 ea];
x1=x2;
es = 0.0001;
n= 100;
for i = 2:n
fx1 = subs (fx,x,x1); % mensubtitiuskan xl ke fxl
fy1 = subs (fy,x,x1);
x2 = x1-(fx1/fy1);
ea = abs (x2-x1)/x2;
N = [N;x1 x2 ea];
x1=x2;
if ea<es
break
end
end
N
False_Position_Methods
Diposting oleh
Unknown
/
Comments: (0)
%False_Position_Methods
syms x
fx = x^2+x-3;
%fx = x^3-0.165*x^2+3.993*10^-4;
xl = 1;
xu = 2;
fxl = subs (fx,x,xl);
fxu = subs (fx,x,xu);
xr = (fxl*xu-fxu*xl)/(fxl-fxu);
n = 100;
ea = 0.0001;
es = 1;
N = [xl xu xr es];
for i = 1:n
fxl = subs (fx,x,xl);
fxu = subs (fx,x,xu);
xr = (fxl*xu-fxu*xl)/(fxl-fxu);
fxr = subs (fx,x,xr);
if fxl*fxr < 0
es = abs((xr - xl)/xr);
xu = xr;
else
es = abs((xr - xu)/xr);
xl = xr;
end
if es<ea
break
end
N = [N; xl xu xr es];
end
N
x= 1:101;
plot (x',N(:,4),'O')
grid on
syms x
fx = x^2+x-3;
%fx = x^3-0.165*x^2+3.993*10^-4;
xl = 1;
xu = 2;
fxl = subs (fx,x,xl);
fxu = subs (fx,x,xu);
xr = (fxl*xu-fxu*xl)/(fxl-fxu);
n = 100;
ea = 0.0001;
es = 1;
N = [xl xu xr es];
for i = 1:n
fxl = subs (fx,x,xl);
fxu = subs (fx,x,xu);
xr = (fxl*xu-fxu*xl)/(fxl-fxu);
fxr = subs (fx,x,xr);
if fxl*fxr < 0
es = abs((xr - xl)/xr);
xu = xr;
else
es = abs((xr - xu)/xr);
xl = xr;
end
if es<ea
break
end
N = [N; xl xu xr es];
end
N
x= 1:101;
plot (x',N(:,4),'O')
grid on