2016上海大学数值方法报告.doc
文本预览下载声明
2013-2014学年冬季学期
数值方法实验报告
组 别 第X组
学 号 1212XXX
姓 名 XXXX
指导老师 XXXX
完成日期 201X.XXX
实验一
题目
P31
1.根据习题12和习题13构造算法和MATLAB程序,以便精确计算所有情况下的二次方程的根,包括的情况。
2.参照例1.25,对下列3个序列求序列,请计算出前10个数值近似值。构造类似表1.4、表1.5以及图1.8至图1.10的输出。
(a) ;,初始误差为0.00 2其中n=1,2,…
(b) ,,,初始误差为0.003,其中n=2,3,…
代码
第一题:
第二题:
结果
1、
2、
总结
本次作业的目的在于熟悉我们对Matlab基本的操作。第一题是对if…else…的应用。第二题是画图和格式输出。
实验二
一、题目
P40
1. 使用程序2.1求解下面每个函数的不动点(尽可能多)近似值,答案精确到小数点后12位。同时,构造每个函数和直线y=x来显示所有不动点。
(a)
(b)
(c)
(d)
P49
修改程序2.2和程序2.3,使得输出分别类似于表2.1和表2.2的矩阵(即矩阵的第一行应当为[0 ] )
二、代码
第一题:此题包含了文件fixpt.m 、plotfixpt.m 、sqrtm.m 、main1.m
fixpt.m
plotfixpt.m
sqrtm.m
main1.m
function main
figure(1)
hold off
grid on
axis([-2 2.5 -2 2.5]);
axis square
hold on
g=inline(x.^5-3*x.^3-2*x.^2+2);
x=[-2:0.01:2.5];
plot(x,g(x),r);
plot(x,x,g);
f1=inline(sqrtm(3*x.^3+2*x.^2+x-2,5));
plot(x,f1(x),b);
f2=inline(sqrtm((x.^5-2*x.^2-x+2)/3,3));
plot(x,f2(x),c);
f3=inline(sqrt((x.^5-3*x.^3-x+2)./2));
plot(x,f3(x),m);
text(-0.9,-0.9,y=x);
text(-0.4,2.1,g(x)=x^5-3x^3-2*x^2+2);
text(-1.3,-1.6,f1(x)=(3x^3+2x^2+x-2)^0^/^5);
text(-0.9,0.3,f2(x)=((x^5-2x^2-x+2)/3)^1^/^3);
text(-1,1.6,f3(x)=((x^5-3x^3-x+2)/2)^1^/^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2)
hold off
grid on
axis([-2 2.5 -2 2.5]);
axis square
hold on
[k,p,err,P]=plotfixpt(f1,0.9,0.00001,100,k);
[k,p,err,P]=plotfixpt(f1,0.6,0.00001,100,k);
plot(x,g(x),r);
plot(x,x,g);
plot(x,f1(x),b);
text(-0.9,-0.9,y=x);
text(-0.4,2.1,g(x)=x^5-3x^3-2*x^2+2);
text(-1.3,-1.6,f1(x)=(3x^3+2x^2+x-2)^0^/^5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(3)
hold off
grid on
axis([-2 2.5 -2 2.5]);
axis square
hold on
[k,p,err,P]=plotfixpt(f2,-1,0.00001,100,k);
plot(x,g(x),r);
plot(x,x,g);
plot(x,f2(x),c);
text(-0.9,-0.9,y=x);
text(-0.4,2.1,g(x)=x^5-3x^3-2*x^2+2);
text(-0.9,0.3,f2(x)=((x^5-2x^2-x+2)/3)^1^/^3);
main2
function main
figure(1)
hold off
grid on
显示全部