常州大学数值分析第一章习题解答

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.1解:

m=3;

f=@(x)digit(digit(x^4,m)- digit(x^3,m)+ digit(3*x^2,m)+ digit(x-2,m),m);

g=@(x)digit(digit(digit( digit(digit(digit( (x-1)*x,m)+3,m)*x,m)+1,m)*x,m)-2,m);

f(3.33)

g(3.33)

有ans = 121

ans =121

实际上,当m=2时,就可以看出这两种算法在计算的精确度上的区别:

m=2;

f=@(x)digit(digit(x^4,m)- digit(x^3,m)+ digit(3*x^2,m)+ digit(x-2,m),m);

g=@(x)digit(digit(digit( digit(digit(digit( (x-1)*x,m)+3,m)*x,m)+1,m)*x,m)-2,m);

f(3.33)

g(3.33)

有ans = 120

ans =130,可以看出,两者在计算精度上的不同区别,数学上恒等,在数值上不一定恒等。

1.2解:

(1)精确到小数点后第三位,故有4位有效数字

(2)精确到小数点后第三位,故有2位有效数字

(3)精确到小数点后第三位,故有0位有效数字

1.3 解;

记圆的面积为S,由题意有|e(S)|≤1%。由S=πr2知:dS=2πrdr所以

dS/S=(2πrdr)/(πr2)=2(dr/r)

∴|e(r)|≈1/2|e(S)|≤0.5×1%=0.5%

1.4 解:

由题有:|e(x)|≤1/2×10^-2 ; |e(y)|≤1/2×10^-2; |e(z)||≤1/2×10^-2

∴|e(S)|≈|xe(x)+ye(y)|+ |ze(z)|^2≈x|e(x)|+y|e(y)|+z^2|z(z)|^2≤4.21×0.005+1.79×1.005+2.11×2.11×0.005^2=0.03≤1/2×10^-1

又S=4.21*1.79+2.11^2=11.988

∴S至少具有3位有效数字。

在字长为3的计算机上运行,误差为:

S1=4.21*1.79+2.11;

S2=digit(digit(4.21*1.79,3)+digit(2.11^2,3),3);

err=S1-S2

err = -2.3541

1.6 解:

clc

disp('Please input the coefficients of');

disp('quadratic equation ax^2+bx+c=0, respectively')

a=input('a=');

b=input('b=');

c=input('c=');

m=4; % m-digit rounding arithmetic

if abs(a)

error('incorrect input')

end

if abs(a)

disp('Since a=0, quadrtic equation degenerates into a linear equation.')

disp('The only solution of the linear eqution is')

x=digit(-c/b,m)

return

end

delta=b^2-4*a*c;

temp=sqrt(delta);

if b>0

x1=(-b-temp)/(2*a)

end

if b<0

x1=(-b+temp)/(2*a)

end

if b==0

x1=temp/(2*a)

end

x2=(c/a)/x1

在输入a=1,b=-112,c=2后有结果x1 =111.9821

x2 =0.0179

1.8方法一:00!!n n

k x n n x x e n n ∞

===≈∑∑,x -∞<<+∞ 方法二:00()()1/1/1/!!n n

k x x

n n x x e e n n ∞-==--==≈∑∑,x -∞<<+∞, clc;

%Initialize the data

x=5;

k=10;

m=4; %three-digit rounding arithmetic

%------------------------------------

% Compute exp(x) by using Method (A)

% with the computer precision

results_1=1;

power_x=1;

for i=1:k

factor_x=x/i;

power_x=power_x*factor_x;

results_1=results_1+power_x;

end

results_1

err_1=abs(exp(x)-results_1)

%------------------------------------

% Compute exp(x) by using Method (A)

% with the 3-digits precision

results_2=1;

power_x=1;

for i=1:k

factor_x=digit(x/i,m);

power_x=digit(power_x*factor_x,m);

results_2=digit(results_2+power_x,m);

end

results_2

err_2=abs(exp(x)-results_2)

%------------------------------------

% Compute exp(x) by using Method (B)

% with the computer precision

t=-x;

results_3=1;

power_x=1;

for i=1:k

factor_x=t/i;

power_x=power_x*factor_x;

results_3=results_3+power_x;

end

results_3=1/results_3

err_3=abs(exp(x)-results_3)

%------------------------------------

% Compute exp(x) by using Method (B)

% with the 3-digits precision

t=-x;

results_4=1;

power_x=1;

for i=1:k

factor_x=digit(t/i,m);

power_x=digit(power_x*factor_x,m);

results_4=digit(results_4+power_x,m);

end

results_4=digit(1/results_4,m)

err_4=abs(exp(x)-results_4)

%------------------------------------

上述程序用公式(1)及(2)分别在Matlab许可精度下及限定在字长为4的算术运算情况下给出的近似计算结果,其中results_1, results_2为用方法(1)在上述两种情况下的计算结果,err_1, err_2为相应的绝对误差;类似的,results_3, results_4为用方法(2)在上述

相关文档
最新文档