资源描述:
《实验3-追赶法解三对角方程组-2.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、《数值分析》实验3一.实验名称:追赶法二、实验目的:(1)学会用追赶法解三对角方程组。三、实验要求(1)按照题目要求完成实验内容(2)写出相应的C语言程序(3)给出实验结果(4)写出相应的实验报告四、实验题目1.追赶法解线性方程组2.用追赶法解下列n阶方程组取n=10和n=100。#include#includeintmain(){intn=10,i,j,m=n+1;floata[m][m],u[m][m],l[m][m],t,x[m],y[m],b[m],d=1,e=-4,f=1;for(i=2;i<=n;i++)b[i]=-15;b[1]=-2
2、7;for(i=2;i<=n;i++){a[i][i-1]=d;//2,1_n,n-1a[i-1][i-1]=e;//1,1_n-1,n-1a[i-1][i]=f;//1,2_n-1,n}a[n][n]=e;//n,nu[1][1]=a[1][1];for(i=2;i<=n;i++){l[i][i-1]=a[i][i-1]/u[i-1][i-1];u[i][i]=a[i][i]-l[i][i-1]*a[i-1][i];}y[1]=b[1];for(i=2;i<=n;i++)y[i]=b[i]-l[i][i-1]*y[i-1];x[n]=y[n]/u[n][n];for(i=n-1;
3、i>=1;i--)x[i]=(y[i]-a[i][i+1]*x[i+1])/u[i][i];for(i=1;i<=n;i++)printf("x[%d]=%f",i,x[i]);}x[1]=8.705771x[2]=7.823085x[3]=7.586571x[4]=7.523196x[5]=7.506216x[6]=7.501665x[7]=7.500446x[8]=7.500119x[9]=7.500031x[10]=7.500008x[11]=7.500002x[12]=7.500000x[13]=7.500000x[14]=7.500000x[15]=7.500000x
4、[16]=7.500000x[17]=7.500000x[18]=7.500000x[19]=7.500000x[20]=7.500000x[21]=7.500000x[22]=7.500000x[23]=7.500000x[24]=7.500000x[25]=7.500000x[26]=7.500000x[27]=7.500000x[28]=7.500000x[29]=7.500000x[30]=7.500000x[31]=7.500000x[32]=7.500000x[33]=7.500000x[34]=7.500000x[35]=7.500000x[36]=7.500000x
5、[37]=7.500000x[38]=7.500000x[39]=7.500000x[40]=7.500000x[41]=7.500000x[42]=7.500000x[43]=7.500000x[44]=7.500000x[45]=7.500000x[46]=7.500000x[47]=7.500000x[48]=7.500000x[49]=7.500000x[50]=7.500000x[51]=7.500000x[52]=7.500000x[53]=7.500000x[54]=7.500000x[55]=7.500000x[56]=7.500000x[57]=7.500000x
6、[58]=7.500000x[59]=7.500000x[60]=7.500000x[61]=7.500000x[62]=7.500000x[63]=7.500000x[64]=7.500000x[65]=7.500000x[66]=7.500000x[67]=7.500000x[68]=7.500000x[69]=7.500000x[70]=7.500000x[71]=7.500000x[72]=7.500000x[73]=7.500000x[74]=7.500000x[75]=7.500000x[76]=7.500000x[77]=7.500000x[78]=7.500000x
7、[79]=7.500000x[80]=7.500000x[81]=7.500000x[82]=7.500000x[83]=7.500000x[84]=7.500000x[85]=7.500000x[86]=7.500000x[87]=7.500000x[88]=7.500000x[89]=7.499999x[90]=7.499996x[91]=7.499986x[92]=7.499947x[93]=7.499801x[94]=7.499256x[95]=7.49722