现在时间是:
当前位置:首 页 >> 数值分析(英)>> 教学区>> 文章列表

17074189 作业9

作者:17074189   发布时间:2019-06-23 20:11:58   浏览次数:20

5.1 Exercises
2. Use the three-point centered-difference formula to approximate f(0), where f(x)=ex, for (a) h=0.1 (b) h=0.01 (c) h=0.001.
结果:(1The three-point centered-difference formula evaluates to f(x)[ f(x + h)  f(x  h) ]/(2h) = (e^0.1-e^-0.1)/0.21.0016675005. 
(2)The three-point centered-difference formula evaluates to f(x)[ f(x + h)  f(x  h) ]/(2h) = (e^0.01-e^-0.01)/0.021.000016665. 
(3)The three-point centered-difference formula evaluates to f(x)[ f(x + h)  f(x  h) ]/(2h) = (e^0.001-e^-0.001)/0.0020.100000015. 
5.1 Computer Problems
2. Use the three-point centered-difference formula to approximate f(0), where f(x)=ex, for (a) h=0.1 (b) h=0.01 (c) h=0.001. 
代码:function y=tpcd(f,x,h)
y=(f((x)+h)-f((x)-h))/2*h;
结果:>> f=@(x) exp(x);
(a)>> y=tpcd(f,0,0.1)
 
y =
 
    0.0100
 
(b)>> y=tpcd(f,0,0.01)
 
y =
 
   1.0000e-04
 
(c)>> y=tpcd(f,0,0.001)
 
y =
 
   1.0000e-06
 
5.2 Exercises
1. Apply the composite Trapezoid Rule with m=1,2, and 4 panels to approximate the integral. Compute the error by comparing with the exact value from calculus. (b) 
结果:For the composite Trapezoid Rule on[0,π/2], one panels means that h=π/2. The approximation is
≈((π/2)/2)*[y0+y1]=π/4
The errors is -π^3*cos1/96.
For the composite Trapezoid Rule on[0,π/2], two panels means that h=π/4. The approximation is
≈((π/4)/2)*[y0+y2+2*]=(π/8)*(1+2)
The errors is -π^3*cos1/384.
 
For the composite Trapezoid Rule on[0,π/2], four panels means that h=π/8. The approximation is
≈((π/4)/2)*[y0+y2+2*]=(π/8)*(1+2+2*cos(π/8)+2*cos(3π/8))
The errors is -π^3*cos1/1536.
 
2. Apply the Composite Midpoint Rule with m=1,2, and 4 panels to approximate the integrals in Exercise 1, and report the errors. 
结果:First note that we cannot apply a closed method directly to the problem, without special handling at x =0. The midpoint method can be applied directly. 
f’’(x)=-cosx.
When m=1, the midpoints are π/4, the Composite Midpoint Rule delivers
≈(π/2)*f(π/4)=√2π/4.
h=π/2,
The errors is -π^3*cos1/192.
When m=2, the midpoints are π/8,3π/8, so the Composite Midpoint Rule delivers 
≈(π/4)*=(π/4)*(cos(π/8)+cos(3π/8)).
h=π/4,
The errors is -π^3*cos1/768.
When m=4, the midpoints are π/16,3π/16,5π/16,7π/16, so the Composite Midpoint Rule delivers 
≈(π/8)*=(π/8)(cos(π/16)+cos(3π/16)+cos(5π/16)+cos(7π/16)).
h=π/8,
The errors is -π^3*cos1/3072.
 
3. Apply the composite Simpsons Rule with m=1,2, and 4 panels to the integrals in Exercise 1, and report the errors.
结果:
(b) A one-panel Simpsons Rule sets h=π/2. The approximation is
π/6*[y0+y2+4*y1]=π/6*[1+0+2*2^(1/2)]=π/6*[1+2*2^(1/2)]
The errors is π^5/5760.
A two-panel Simpsons Rule sets h=π/4. The approximation is
π/12*[y0+y4+4*(y1+y3)+2*y2]=π/12*[1+0+4*(cos(π/8)+cos(3π/8))+2^(1/2)]=π/12*[1+4*(cos(π/8)+cos(3π/8))+2^(1/2)]
The errors is π^5/92160.
 A four-panel Simpsons Rule sets h=π/8. The approximation is
π/24*[y0+y8+4*(y1+y3+y5+y7)+2*(y2+y4+y6)]=π/24*[1+0+4*(cos(π/16)+cos(3π/16)+cos(7π/16))+2*(cos(π/8)+(2^(1/2))/2+cos(3π/8))]=π/24*[1+4*(cos(π/16)+cos(3π/16)+cos(7π/16))+2*(cos(π/8)+(2^(1/2))/2+cos(3π/8))]
The errors is π^5/1474560.
 
 4. Apply the composite Simpsons Rule with m=1,2, and 4 panels to the integrals, and report the errors. (b)
结果:(b) A one-panel Simpsons Rule sets h=1. The approximation is
≈1/3*[y0+y2+4*y1]=1/3*[1+(1/2)+(16/5)]=47/30
The errors is 3/4.
A two-panel Simpsons Rule sets h=1/2. The approximation is
≈1/6*[y0+y4+4*(y1+y3)+2*y2]=1/6*[1+(1/2)+4*((16/17)+(16/25))+2^(4/5)]=195/34
The errors is 3/16.
 A four-panel Simpsons Rule sets h=1/4. The approximation is
≈1/12*[y0+y8+4*(y1+y3+y5+y7)+2*(y2+y4+y6)]=1/12*[1+(1/2)+4*((64/65)+(64/73)+(1/64/89)+(64/113))+2*((16/17)+(4/5)+(16/25))]=22.688291286
The errors is 3/64.
 
5.2 Computer Problems 
1. Use the composite Trapezoid Rule with m=16 and 32 panels to approximate the denite integral. Compare with the correct integral and report the two errors. 
 (d) 
 (h)  
分析:
代码:function y=CTR(f,m,a,b)
h=(b-a)/m;
for i=1:m+1
    x(i)=a+(i-1)*h;
end
y=f(x(1))+f(x(m+1));
for i=2:m
    y=y+2*f(x(i));
end
y=y*h/2;
结果:(d)
>>  f=@(x) x^2*exp(x);
>> y=CTR(f,16,1,3)
 
y =
 
   98.0909
>> y=CTR(f,32,1,3)
 
y =
 
   97.8048
(h)
>> f=@(x) x/(x^4+1)^(1/2);
>> y=CTR(f,16,0,1)
 
y =
 
    0.4404
 
>> y=CTR(f,32,0,1)
 
y =
 
    0.4406
 
2. Apply the composite Simpsons Rule to the integrals in Computer Problem 1. Use m=16 and 32, and report errors. 
代码:function y=CSR(f,a,b,m)
h=(b-a)/(2*m);
for i=1:2*m+1
    x(i)=a+(i-1)*h;
end
y=f(x(1))+f(x(2*m+1));
for i=2:2:2*m
    y=y+4*f(x(i));
end
for i=3:2:2*m+1
    y=y+2*f(x(i));
end
y=y*h/3;
结果:(d)
>> f=@(x) x^2*exp(x);
>> y=CSR(f,1,3,16)
 
y =
 
  105.2415
 
>> y=CSR(f,1,3,32)
 
y =
 
  101.4754
 
h>> f=@(x) x/(x^4+1)^(1/2);
>> y=CSR(f,0,1,16)
 
y =
 
    0.4554
 
>> y=CSR(f,0,1,32)
 
y =
 
    0.4481
3. Use the composite Trapezoid Rule with m=16 and 32 panels to approximate the denite integral. 
(a) 
(f)  
 
代码:function y=CTR(f,m,a,b)
h=(b-a)/m;
for i=1:m+1
    x(i)=a+(i-1)*h;
end
y=f(x(1))+f(x(m+1));
for i=2:m
    y=y+2*f(x(i));
end
y=y*h/2;
结果:
(a)>> f=@(x) exp(x^2);
>> y=CTR(f,16,0,1)
 
y =
 
    1.4644
 
>> y=CTR(f,32,0,1)
 
y =
 
    1.4631
 (f)>> f=@(x) cos(x)*exp(x);
>> y=CTR(f,16,0,pi)
 
y =
 
  -12.1480
 
>> y=CTR(f,32,0,pi)
 
y =
 
  -12.0897
4. Apply the composite Simpsons Rule to the integrals of Computer Problem 3, using m=16
代码:function y=CSR(f,a,b,m)
h=(b-a)/(2*m);
for i=1:2*m+1
    x(i)=a+(i-1)*h;
end
y=f(x(1))+f(x(2*m+1));
for i=2:2:2*m
    y=y+4*f(x(i));
end
for i=3:2:2*m+1
    y=y+2*f(x(i));
end
y=y*h/3;
结果:
(a)>> f=@(x) exp(x^2);
>> y=CSR(f,0,1,16)
 
y =
 
    1.5193
 
>> y=CSR(f,0,1,32)
 
y =
 
    1.4910
 
(f)>> f=@(x) cos(x)*exp(x);
>> y=CSR(f,0,pi,16)
 
y =
 
  -13.5849
 
>> y=CSR(f,0,pi,32)
 
y =
 
  -12.8276
 
5.3 Exercises
1. Apply Romberg Integration to nd R33 for the integrals. 
(c)  
结果:
h1=b-a=1;
h2=(1/2)*(b-a)=1/2;
h3=(1/4)*(b-a)=1/4;
 
R11=h1/[f(a)+f(b)]=e+1;
R21=h2/[f(a)+f(b)+2*f((a+b)/2))]=(e+1)/2+e^(1/2);
R31=(1/2)*R21+h3*=(1/4)*(e+1+2*e^(1/2)+e^(1/4)+e^(3/4));
R22=[(2^2)R21-R11]/3=(1/3)*[e+1+4*e^(1/2)]
R32=[(2^2)R31-R21]/3=(1/2)*[e+1+2*e^(1/2)]+e^(1/4)+e^(3/4);
R33=[(4^2)*R32-R22]/[(4^2)-1]=[23*(e+1)+44*e^(1/2)]/45+[16*(e^(1/4)+e^(3/4)]/15;
6.1Exercises
3. Use separation of variables to find solutions of the IVP given by y(0)=1 and the following differential equations: (a) y′=t (b) y′=(t^2)*y (c) y′=2*(t + 1)*y (d) y′=5*(t^4)*y (e) y′=1/(y^2) (f) y′=t^3/y^2
结果:
(a) Separate variables, y′=dy/dt=t
                          dy=tdt
                          y=(1/2)*t^2+c, c is a constant.
Because of y(0)=1, c=1, to sum up y=(1/2)*t^2+1.
(b) Separate variables, y′=dy/dt= y′=(t^2)*y 
                          dy/y=t^2dt
                          ln|y|=(1/3)*(t^3)+c, c is a constant.
                           |y|=e^[(1/3)*(t^3)+c]
Because of y(0)=1, c=0, to sum up y=e^[(1/3)*(t^3)].
(c) Separate variables, y′=dy/dt= y′=2*(t + 1)*y  
                          dy/y=2*(t+1)dt
                          ln|y|=t^2+2*t+c, c is a constant.
                           |y|=e^[t^2+2*t+c]
Because of y(0)=1, c=0, to sum up y=e^[t^2+2*t].
(d) Separate variables, y′=dy/dt= y′=5*(t^4)*y 
                          dy/y=5*(t^4)dt
                          ln|y|=t^5+c, c is a constant.
                           |y|=e^[t^5+c]
Because of y(0)=1, c=0, to sum up y=e^[t^5].
e of y(0)=1, c=0, to sum up y=e^[t^2+2*t].
(e) Separate variables, y′=dy/dt= y′=1/(y^2)
                          y^2dy=dt
                          (1/3)y^3=t+c, c is a constant.
                           y=(3*(t+c))^(1/3)
Because of y(0)=1, c=1/3, to sum up y=(3*t+1)^(1/3).

 

(f) Separate variables, y′=dy/dt= y′=t^3/y^2
                          y^2dy=t^3dt
                          (1/3)y^3=(1/4)*(t^4)+c, c is a constant.
                           y=[(3/4)*(t^4)+(3*c)]^(1/3)
Because of y(0)=1, c=1/3, to sum up y=[(3/4)*(t^4)+1]^(1/3).
 
 5. Apply Euler’s Method with step size h=1/4 to the IVPs in Exercise 3 on the interval [0,1]. List the wi,i =0,...,4, and find the error at t =1 by comparing with the correct solution. 
结果:
(a) The right-hand side of the differential equation is f(t,y)=t. Therefore, Eulers Method will be the iteration
w0=1, w(i+1)=wi + h*ti. Using the grid with step size h=1/4, we calculate the approximate solution iteratively . The values wi given by Eulers Method and plotted in Figure are compared with the true values yi in the following table:
Step     ti     wi        yi          ei
0        0     1         1          0
1       1/4    1+(1/16)   1+(1/32)   1/32
2       2/4    1+(3/16)   1+(1/8)    1/16
3       3/4    1+(6/16)   1+(9/32)   3/32
4        1     1+(10/16)  1+(1/2  1/8
When t=1, errors is 1/8.
(b) The right-hand side of the differential equation is f(t,y)=t. Therefore, Eulers Method will be the iteration
w0=1, w(i+1)=wi + h*ti. Using the grid with step size h=1/4, we calculate the approximate solution iteratively . The values wi given by Eulers Method and plotted in Figure are compared with the true values yi in the following table:
Step  ti   wi                         yi          ei
0     0   1                          1          0
1    1/4  1+(1/4)*e^(1/192)            e^(1/192)  1-(3/4)*e^(1/192)
2    2/4  1+(1/4)*[e^(1/24)+e^(1/192)]  e^(1/24)   1-(3/4)*e^(1/24)+(1/4)*e^(192)
3    3/4  1+(1/4)*[e^(1/24)+e^(1/192)+  e^(9/64)  1-(3/4)*e^(9/64)+(1/4)*[e^(1/24)+                   
          e^(9/64)]                              e^(1/192)]
4     1   1+(1/4)*[e^(1/24)+e^(1/192)+  e^(1/3)   1-(3/4)*e^(1/3)+(1/4)*[e^(1/24)+                   
          e^(9/64)+e^(1/3)]                       e^(9/64) +e^(1/192)]
When t=1, errors is 1-(3/4)*e^(1/3)+(1/4)*[e^(1/24)+ e^(9/64) +e^(1/192)].
(c) The right-hand side of the differential equation is f(t,y)=t. Therefore, Eulers Method will be the iteration
w0=1, w(i+1)=wi + h*ti. Using the grid with step size h=1/4, we calculate the approximate solution iteratively . The values wi given by Eulers Method and plotted in Figure are compared with the true values yi in the following table:
Step  ti   wi                         yi          ei
0     0   1                          1          0
1    1/4  1+(1/4)*e^(1/192)            e^(1/192)  1-(3/4)*e^(1/192)
2    2/4  1+(1/4)*[e^(1/24)+e^(1/192)]  e^(1/24)   1-(3/4)*e^(1/24)+(1/4)*e^(192)
3    3/4  1+(1/4)*[e^(1/24)+e^(1/192)+  e^(9/64)  1-(3/4)*e^(9/64)+(1/4)*[e^(1/24)+                   
          e^(9/64)]                              e^(1/192)]
4     1   1+(1/4)*[e^(1/24)+e^(1/192)+  e^(1/3)   1-(3/4)*e^(1/3)+(1/4)*[e^(1/24)+                   
          e^(9/64)+e^(1/3)]                       e^(9/64) +e^(1/192)]
When t=1, errors is 1-(3/4)*e^(1/3)+(1/4)*[e^(1/24)+ e^(9/64) +e^(1/192)].
 
6.2Exercises
1. Using initial condition y(0)=1 and step size h=1/4, calculate the Trapezoid Method approximation w0,...,w4 on the interval[0,1]. Find the error at t =1 by comparing with the correct solution found in Exercise 6.1.3.  (a) y′=t (b) y′=(t^2)*y (c) y′=2*(t + 1)*y (d) y′=5*(t^4)*y (e) y′=1/(y^2) (f) y′=t^3/y^2
结果:
w0=y0;
w(i+1)=wi+h/2(f(ti,wi)+f(ti+h,wi+hf(ti,wi)))
(a)  
w0=1
w1= w0+h/2(f(t0,w0)+f(t0+h,w0+hf(t0,w0)))=33/32
w2= w1+h/2(f(t1,w1)+f(t1+h,w1+hf(t1,w1)))=9/8
w3= w2+h/2(f(t2,w2)+f(t2+h,w2+hf(t2,w2)))=41/32
w4= w3+h/2(f(t3,w3)+f(t3+h,w3+hf(t3,w3)))=3/2
e=|y-w4|=0
(b)
w0=1
w1= w0+h/2(f(t0,w0)+f(t0+h,w0+hf(t0,w0)))=129/128
w2= w1+h/2(f(t1,w1)+f(t1+h,w1+hf(t1,w1)))=274641/262144
w3= w2+h/2(f(t2,w2)+f(t2+h,w2+hf(t2,w2)))=622061865/536870912
w4= w3+h/2(f(t3,w3)+f(t3+h,w3+hf(t3,w3)))=1.405352734454937
e=|y-w4|=0.009740309368848
 
(c)
w0=1
w1= w0+h/2(f(t0,w0)+f(t0+h,w0+hf(t0,w0)))=1.718750000000000
w2= w1+h/2(f(t1,w1)+f(t1+h,w1+hf(t1,w1)))=3.303222656250000
w3= w2+h/2(f(t2,w2)+f(t2+h,w2+hf(t2,w2)))=7.070960998535156
w4= w3+h/2(f(t3,w3)+f(t3+h,w3+hf(t3,w3)))=16.793532371520996
e=|y-w4|=3.292004551666672
 
(d)
w0=1
w1= w0+h/2(f(t0,w0)+f(t0+h,w0+hf(t0,w0)))=1.002441406250000
w2= w1+h/2(f(t1,w1)+f(t1+h,w1+hf(t1,w1)))=1.044237840920687
w3= w2+h/2(f(t2,w2)+f(t2+h,w2+hf(t2,w2)))=1.307663471185293
w4= w3+h/2(f(t3,w3)+f(t3+h,w3+hf(t3,w3)))=2.706793149522585
e=|y-w4|=0.011488678936460
 
(e)
w0=1
w1= w0+h/2(f(t0,w0)+f(t0+h,w0+hf(t0,w0)))=1.205000000000000
w2= w1+h/2(f(t1,w1)+f(t1+h,w1+hf(t1,w1)))=1.356993862239376
w3= w2+h/2(f(t2,w2)+f(t2+h,w2+hf(t2,w2)))=1.480971731811849
w4= w3+h/2(f(t3,w3)+f(t3+h,w3+hf(t3,w3)))=1.587101493145249
e=|y-w4|=2.995588229504076e-04
 
(f)
w0=1
w1= w0+h/2(f(t0,w0)+f(t0+h,w0+hf(t0,w0)))=1.001953125000000
w2= w1+h/2(f(t1,w1)+f(t1+h,w1+hf(t1,w1)))=1.019342601468375
w3= w2+h/2(f(t2,w2)+f(t2+h,w2+hf(t2,w2)))=1.082264953617726
w4= w3+h/2(f(t3,w3)+f(t3+h,w3+hf(t3,w3)))=1.218241931698513
e=|y-w4|=0.013170799610898
 
 
 







上一篇:没有了    下一篇:没有了

Copyright ©2019    计算数学达人 All Right Reserved.

技术支持:自助建站 | 领地网站建设 |短信接口 |燕窝 版权所有 © 2005-2019 lingw.net.粤ICP备16125321号 -5