欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

北航数值分析第一次大作业—C语言

程序员文章站 2022-07-11 20:21:21
...
# include <stdio.h>
# include <stdlib.h>
# include <math.h>

/*n维向量相乘得到实数的运算*/
double vecTimes(double *a, double *b, int n) {
    int i;
    double sum;
    sum = 0;
    for (i=1;i<=n;i++)
        sum += a[i] * b[i];
    return sum;
}

/*计算矩阵的无穷范数*/
int vecLimitNorm(double *a, int n) {
    int i,r;
    double maxa;
	maxa = fabs(a[1]);
	r = 1;
    for (i=1;i<n;i++)
        if (fabs(a[i])>maxa) {
			maxa = fabs(a[i]);
			r = i;
		}
    return r;
}

/*根据t计算矩阵A的值*/
void setMatrixA(double **A, int n,double t) {
    int i,j;
    for (i=1;i<=n;i++)
        for (j=1;j<=n;j++)
            if (i==j)
                A[i][i] = (double)100*((double)i+0.1)/((double)i+t);
            else if (j>i && i>=j-3 && i>=1)
                A[i][j] = -(double)(i+j)/((double)1+t);
            else if (i>j && i<=j+3 && i<=n)
                A[i][j] = -(double)(i+j)/((double)1+t);
            else