Sei sulla pagina 1di 3

clear,clc

fun=@(x) tan(x)+x;
x=linspace(0,20*pi,100000);
plot(x,tan(x),'linewidth',2)
hold on;
plot(x,-x,'linewidth',2)
grid on
title('122516 �ӿ��� Chpter.7 Ex')
legend('tan(x)','-x')
axis([0 20*pi -20*pi 20*pi])
set(gca, 'xtick', [0:2*pi:20*pi])
set(gca, 'ytick', [-20*pi:4*pi:20*pi])
x=zeros(1,21)';
tol=1e-8;
iter=1;
lambda=zeros(1,20)';
format long
for n=1:20
x(n+1)=n*pi;
end

% bisection8�� ��; � Code


for i=1:20
x1=x(i)+pi/2+(1e-4); x2=x(i+1)-(1e-3); %�߻�
��� ���ʱ� '�� �ʱⰪ ��d
while 1
f1=fun(x1);
f2=fun(x2);
iter=iter+1;
x3=(x1+x2)/2; f=fun(x3);
if f1*f<0
x2=x3; f2=f;
else
x1=x3; f1=f;
end
if abs(x2-x1)<tol, break, end %�� ���� �� 10^-8���� ��8��
����Ͽ� ��;ã=
end
lambda(i)=x3; %ã: ��; ��‫� �ٷ‬Է�
end
lambda; % ��~��8�� ã: ���

An=zeros(1,20)';
for i=1:20
An(i)=4*(sin(lambda(i))-lambda(i)*cos(lambda(i)))/(lambda(i)*(2*lambda(i)-
sin(lambda(i)))); % An�� ��Ŀ� ��‫���� �ٸ‬
end
An; % ��dw8�� ã: An

x=linspace(0,1.1,1000);
t=linspace(0,1,11);
u1=zeros(20,1000);
for i=1:20
for k=1:995
u1(i,k)=An(i)*exp(-(lambda(i)^2)*t(1))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
A=sum(u1);
u2=zeros(20,1000);
for i=1:20
for k=1:1000
u2(i,k)=An(i)*exp(-(lambda(i)^2)*t(2))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
B=sum(u2);
u3=zeros(20,1000);
for i=1:20
for k=1:1000
u3(i,k)=An(i)*exp(-(lambda(i)^2)*t(3))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
C=sum(u3);
u4=zeros(20,1000);
for i=1:20
for k=1:1000
u4(i,k)=An(i)*exp(-(lambda(i)^2)*t(4))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
D=sum(u4);
u5=zeros(20,1000);
for i=1:20
for k=1:1000
u5(i,k)=An(i)*exp(-(lambda(i)^2)*t(5))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
E=sum(u5);
u6=zeros(20,1000);
for i=1:20
for k=1:1000
u6(i,k)=An(i)*exp(-(lambda(i)^2)*t(6))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
F=sum(u6);
u7=zeros(20,1000);
for i=1:20
for k=1:1000
u7(i,k)=An(i)*exp(-(lambda(i)^2)*t(7))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
G=sum(u7);
u8=zeros(20,1000);
for i=1:20
for k=1:1000
u8(i,k)=An(i)*exp(-(lambda(i)^2)*t(8))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
H=sum(u8);
u9=zeros(20,1000);
for i=1:20
for k=1:1000
u2(i,k)=An(i)*exp(-(lambda(i)^2)*t(9))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
I=sum(u9);
u10=zeros(20,1000);
for i=1:20
for k=1:1000
u10(i,k)=An(i)*exp(-(lambda(i)^2)*t(10))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
J=sum(u10);
u11=zeros(20,1000);
for i=1:20
for k=1:1000
u11(i,k)=An(i)*exp(-(lambda(i)^2)*t(11))*sin(lambda(i)*x(k)); %
alpha�� 1��߻����� �Ŀ ��� f��
end
end
K=sum(u11);
figure (2)
plot (x,A,'linewidth',2)
hold on
plot (x,B,'linewidth',2)
plot (x,C,'linewidth',2)
plot (x,D,'linewidth',2)
plot (x,E,'linewidth',2)
plot (x,F,'linewidth',2)
plot (x,G,'linewidth',2)
plot (x,H,'linewidth',2)
plot (x,I,'linewidth',2)
plot (x,J,'linewidth',2)
plot (x,K,'linewidth',2)
grid on
title('122516 �ӿ��� Chpter.7 Result')
legend('t=0','t=0.1','t=0.2','t=0.3','t=0.4','t=0.5','t=0.6','t=0.7','t=0.8','t=0.9
','t=1.0')
axis ( [0 1 0 1.5])
set(gca,'xtick',(0:0.1:1))
set(gca,'ytick',(0:0.1:1.5))

Potrebbero piacerti anche