内容发布更新时间 : 2025/1/7 16:11:16星期一 下面是文章的全部内容请认真阅读。
实验六 迭代(方程求解)
一.实验目的:认识迭代数列,考察迭代数列的收敛性.并学会用Mathematica系统对线性和非线性的方程组进行迭代求解.
二.实验环境:计算机,Mathematica 数学软件,Word文档,课本。 三.实验的基本理论和方法:
给定迭代函数f(x)以及一个初值x0利用xn?1?f(xn),n?0,1,???迭代得到数列xn,n?0,1,???.如果数列xn收敛与某个x,则有x?f(x).即x是方程
****x?f(x)的解.由此用如下的方法求方程g(x)?0的近似解。
将方程g(x)?0改写为等价的方程x?f(x),然后选取一初值利用
xn?1?f(xn),n?0,1,???做迭代.迭代数列xn收敛的极限就是g(x)?0的解.线
性方程组以及非线性方程组的求解与单变量的方程求解方法类似.实验内容和步骤
四.实验内容与结果 1.线性方程组
⑴编写给定初值x0及迭代函数f(x),迭代n次产生相应的序列.
⑵给函数f(x)?(x?2/x)初值为0进行迭代80次所产生的迭代序列并显示. 输入程序:
Iteratef_,x0_,n_Integer:ModuleForit1,i,i,tempn,itfx_:x2x2;x0,ftemp;;AppendTot,temp;,tempAppendTot,tempIteratef,1.,80
运行结果得:
1.,1.5,1.41667,1.41422,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421,1.41421
输入程序:
NTIterateg_,x0_,n_Integer:Modulei,varhx_Fori1,ix0,t,h,Dtgx,x;n,i,AppendTot,var;Nvargvarhvar,20,0,varIfhvarPrint\byZeroafter\i,\iterations.\;Breaktgx_:x^32;; NTIterateg,1,40
运行结果得:
1,1.3333333333333333333,1.2638888888888888889,1.2599334934499769665,1.259921050017769774,1.259921049894873165,1.259921049894873165,1.259921049894873165,1.25992104989487316,1.25992104989487316,1.25992104989487316,1.2599210498948732,1.2599210498948732,1.2599210498948732,1.259921049894873,1.259921049894873,1.259921049894873,1.259921049894873,1.25992104989487,1.25992104989487,1.25992104989487,1.2599210498949,1.2599210498949,1.2599210498949,1.259921049895,1.259921049895,1.259921049895,1.259921049895,1.25992104989,1.25992104989,1.25992104989,1.2599210499,1.2599210499,1.2599210499,1.259921050,1.259921050,1.259921050,1.259921050,1.25992105,1.25992105
2. 非线性方程组
⑴对于给定的矩阵M,数组f和初始向量x,由迭代x代程序,并选择初值分别迭代20和50次所产生的序列. 迭代40次运行结果: 输入程序:
LSIteratem_,f_List,f0_List,n_Integer:Modulei,varForitm1,0.4,0.5,1;f1,1;f00,0;1,if0,tn,iTable,ti,i,n,m.varf;var;var0n?1?Mxn?f编写迭
LSIteratem,f,f0,40
运行结果得:
0,0,1.,1.,2.4,2.5,4.4,4.7,7.28,7.9,11.44,12.54,17.456,19.26,26.16,28.988,38.7552,43.068,56.9824,63.4456,83.3606,92.9368,121.535,135.617,176.782,197.385,256.736,286.776,372.446,416.144,539.904,603.367,782.251,874.319,1132.98,1266.44,1640.56,1833.93,2375.13,2655.21,3438.22,3843.78,4976.73,5563.88,7203.28,8053.25,10425.6,11655.9,15088.9,16869.7,21837.8,24415.1,31604.9,35335.,45739.9,51138.5,66196.3,74009.4,95801.,107109.,138645.,155010.,200650.,224334.,290385.,324660.,420250.,469854.,608192.,679980.,880185.,984077.,1.2738210,1.4241710,1.8434910,2.0610810,2.6679210,2.9828210,3.8610510,4.316781066666666
迭代60次运行结果 输入程序:
LSIteratem_,f_List,f0_List,n_Integer:Modulei,varForitm1,0.4,0.5,1;f1,1;f00,0;1,if0,tn,iTable,ti,i,n,m.varf;var;varLSIteratem,f,f0,60
运行结果得:
1,1.3333333333333333333,1.2638888888888888889,1.2599334934499769665,1.259921050017769774,1.259921049894873165,1.259921049894873165,1.259921049894873165,1.25992104989487316,1.25992104989487316,1.25992104989487316,1.2599210498948732,1.2599210498948732,1.2599210498948732,1.259921049894873,1.259921049894873,1.259921049894873,1.259921049894873,1.25992104989487,1.25992104989487,1.25992104989487,1.2599210498949,1.2599210498949,1.2599210498949,1.259921049895,1.259921049895,1.259921049895,1.259921049895,1.25992104989,1.25992104989,1.25992104989,1.2599210499,1.2599210499,1.2599210499,1.259921050,1.259921050,1.259921050,1.259921050,1.25992105,1.25992105
⑵改写矩阵的等价形式,给定数组f和初始向量x,运用迭代格式
0x?(I?D?1A)x?D?1b编写迭代程序。
输入程序:
JacobIteratea_,b_List,x0_List,n_Integer:ModuleForiForiForjvar1Nb;var;ab3,1,3,21,1;x0;var1;jSumak,adj,kaj,jvark,j,20varad1,i1,i1,jjLengtha,i,j,k,varad,in,iad,j,Ifai,ivar10,;x0,Print\\i,\i,\,0.\;Abort,Printvar;0,0;JacobIteratea,b,x0,10
运行结果得:
0,0
0.33333333333333333333,0.50000000000000000000 0.16666666666666666667,0.1020
0.3333333333333333333,0.2500000000000000000 0.2500000000000000000,0.1020
0.3333333333333333333,0.1250000000000000000 0.291666666666666667,0.1019
0.333333333333333333,0.062500000000000000 0.312500000000000000,0.1018
0.33333333333333333,0.03125000000000000
输入程序: