You are on page 1of 1

clc;

clear;
clf;
l=1;
function a=t(x)
a=cos(n*%pi*x)
endfunction
function b=u(x)
b=sin(n*%pi*x)
endfunction
a0=integrate('1','x',0,1)+integrate('-1','x',-1,0)
disp(a0)
for n=1:50
a(n)=integrate('-t(x)','x',-1,0)+integrate('t(x)','x',0,1)
b(n)=integrate('-u(x)','x',-1,0)+integrate('u(x)','x',0,1)
disp(a(n),"the value of a("+string(n)+") is=")
disp(b(n),"the value of b("+string(n)+") is=")
end
y=a0/2;
x=-15:0.01:15

for n=1:50
y=y+a(n)*cos(n*%pi*x)+b(n)*sin(n*%pi*x);

end
plot2d(x,y)
a=gca();
a.x_location='origin';
a.y_location='origin';

You might also like