码迷,mamicode.com
首页 > 其他好文 > 详细

书本74面方程组求解

时间:2016-12-05 22:36:11      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:ret   double   abs   stdio.h   while   bsp   lib   i++   eps   

#include <stdio.h>
#include <stdlib.h>
#include<math.h>

int main() {
    double x[3]= {0},y[3];
    double fc[3][3]= {{8,-3,2},{4,11,-1},{6,3,12}};
    double g[3]= {20,33,36};
    double eps=0.000001;
    double temp;
    int flag[3]= {1};
    int i;
    do {
        temp=0;
        for(i=0; i<3; i++) {
            flag[i]=0;
            y[i]=x[i];
            x[i]=(g[i]-fc[i][0]*x[0]*flag[0]-fc[i][1]*x[1]*flag[1]-fc[i][2]*x[2]*flag[2])/fc[i][i];
            flag[i]=1;
        }
        for(i=0; i<3; i++) {
            printf("x[%d]=%lf,y[%d]=%lf\n",i,x[i],i,y[i]);
        }
        for(i=0; i<3; i++) {
            if(temp<fabs(y[i]-x[i])) {
                temp=fabs(y[i]-x[i]);
            }
        }
    } while(temp>eps);

    return 0;
}

书本74面方程组求解

标签:ret   double   abs   stdio.h   while   bsp   lib   i++   eps   

原文地址:http://www.cnblogs.com/smallsmallDeng/p/6135478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!