You are on page 1of 4

x=0:0.

01:8;
y=fun(x)

y = 1×801
4.0000 3.9791 3.9582 3.9375 3.9170 3.8965 3.8761 3.8559

figure(1)
plot(x,y,"Linewidth",2)
axis([0 10 0 4])
xlabel('x variable')
ylabel('y variable')

built-in Matlab fucntion

Q = quad(@fun,0,8);
Q

Q = 16.0000

custom summation to compute the integral quadrature integral - Task1

disp('Enter a increment size for the integral, recommended');

Enter a increment size for the integral, recommended

disp('0.1 to 1 (the smaller the better, but');

1
0.1 to 1 (the smaller the better, but

dx=input('smaller requires more computation time)! ... >');

sum=0;
for x=0:dx:8
sum=sum+fun(x)*dx; % 조건반복으로 0에서 8까지 정해준 dx 범위로 곱해나간다.
end

custom summation to compute the integral quadrature integral - Task2

disp('')
disp('The computed integrals of the function y(x) between');

The computed integrals of the function y(x) between

disp('x = 0 and x = 8 are')

x = 0 and x = 8 are

disp(sprintf('quad integral ='));

quad integral =

disp(sprintf(' %f\n custom summation integral = %f', Q, sum))

16.000000
custom summation integral = 16.200000

custom summation to compute the integral quadrature integral - Task3

figure(2)
for x=0:dx:8
patch([x-dx/2; x-dx/2; x+dx/2; x+dx/2], ...
[0; fun(x); fun(x); 0], [0.5 0.5 0.5])
end

2
custom summation to compute the integral quadrature integral - Task4

hold on
x=0:0.01:8;
y=fun(x);
h=plot(x,y,'LineWidth', 2)

h =
Line - 속성 있음:

Color: [0 0.4470 0.7410]


LineStyle: '-'
LineWidth: 2
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1×801 double]
YData: [1×801 double]
ZData: [1×0 double]

모든 속성 표시

axis([0 10 0 4])
xlabel('x variable') % axes labels
ylabel('y variable') % axes labels

3
4

You might also like