1、实验 0 截断误差与舍入误差#include “stdio.h“#include “math.h“const double ln2=0.693147190546;const double e1=5e-6;void main()int sign;double s;long i;s=0.0;sign=1;i=1;while(fabs(ln2-s)=e1)s+=(1.0/i)*sign;sign=-sign;i+;printf(“n=%ldn“,i-1);getch();实验 1 拉格朗日插值法编写拉格朗日插值法通用子程序,并用以下函数表来上机求 , 。)15.0(f)3.(fx 0.0 0.1 0
2、.195 0.3 0.401 0.5f (x) 0.39894 0.39695 0.39142 0.38138 0.36812 0.35206#include main()static float Lx10,Ly10;int n,i,j;float x,y,p;printf(“enter n=“);scanf(“%d“,printf(“enter xin“);for(i=0;i#include float gs(float a2020,float b20,int n )int i,j,k,l;float s;k=1;while(k!=n+1)if(akk!=0)for(i=k+1;i=1;k-
3、)s=0;for(l=k+1;lmain()double x,x0,p=1e-6;double f(double x),g(double x);int i,j,k,n=0;printf(“n enter x0:“);scanf(“%lf“,dox=x0-f(x0)/g(x0);printf(“n %d %12.8lf %8.3le“,n,x0,f(x0);if(np);printf(“n the result is:%lf“,x0);/*MAIN*/double f(double x)return(pow(x,6)-x-1);/*F(X)*/double g(double x)return(6
4、*pow(x,5)-1);/*G(X)*/实验 6 高斯消元法编写选列主元的高斯消去法。求出下列线性方程组 Ax=b 的解 x。472312x#include #define N 10main()int i,ik,k=0,j,l,n,max;static float aNN,bN,t,s,min=1e-6;printf(“n enter n:“);scanf(“%d“,printf(“nenter A=(aij)(line first):“);for(i=0;i=0;i-) for(j=i+1;j#define f(x,y) (x-y)main()float a,b,h,x,y,k1,k2,k
5、3,k4,y0,x0;int n=0,i,j,N;clrscr();printf(“n enter N:“);scanf(“%d“,printf(“nenter a,b:“);scanf(“%f%f“,printf(“n enter primary data y(0): “);scanf(“%f“,h=(b-a)/N;x0=a;printf(“n%10.5f%10.5f“,x0,y0);dox=x0+h;k1=f(x0,y0);k2=f(x0+h/2),(y0+h/2*k1);k3=f(x0+h/2),(y0+h/2*k2);k4=f(x0+h),(y0+h*k3);y=y0+h/6*(k1+2*(k2+k3)+k4);printf(“n%10.5f%10.5f“,x,y);n=n+1;x0=x;y0=y;while(nN);