디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

정말 미치겟습니다 도와주세요 c언어 ㅠㅠ jacobi 프로그램...

아00--아00(99.226) 2012.04.04 10:04:19
조회 571 추천 0 댓글 3

#include <stdio.h>
#include <math.h>
#include <string.h>
/*
Solving a system of linear equations using the Jacobi method.
This program reads in data of the form
3
4.0 0.3 0.5 1.0
2.0 4.0 0.8 2.0
1.0 0.6 9.0 3.0
where the first number N (in this case 3) indicates that the next
N lines will be an augmented matrix N x N+1
The N x N part of the augmented matrix is the matrix of coefficients S
of vector X, and the last column of the augmented matrix is vector T,
such that SX = T
This program uses the Jacobi method to iteratively solve for X.
*/
#define N 8
#define EPSILON 0.0001
void in(double s[][N], double t[], int * n);
void out2D(char * what, double s[][N], int n);
void out1D(char * what, double t[], int n);
void jacobi(double s[][N], double x[], double t[], int n);
void mult(double a[][N], double b[], double result[], int n) ;
char * check(char * name, double sx[], double t[], int n);
main()
{
char name[25] = "Jacobi" ;
double s[N][N], x[N], t[N], sx[N] ;
int i, j, n;
in(s, t, &n);
printf("-----------------------------------------\n") ;
printf("SOLVING S * X = T USING THE JACOBI METHOD\n") ;
printf("-----------------------------------------\n") ;
out2D("S", s, n);
jacobi(s, x, t, n);
mult(s, x, sx, n);
out1D("Jacobi S * X", sx, n);
out1D("original T", t, n);
printf("%s\n", check(name, sx, t, n));
printf("\n\n\n");
}
/*
Reads a value *n which is the dimension of a two dimensional
square matrix, and then reads the n x n matrix s and the vector t
where the data have a shape as shown in the top comment.
*/
void in(double s[][N], double t[], int * n)
{
int i,j;

FILE*in;
in = fopen ("input1.txt","r");
fscanf (in,"%d",&*n);

 for (i=0;i<*n;i++)
   {
  for (j=0;j<*n;j++)
     {
  fscanf (in,"%lf",&s[i][j]);
  }
 fscanf (in,"%lf",&t[i]);
   }
 fclose(in); 
}
/*
Prints a two dimensional square matrix s which is n x n
preceded by the name stored in 'what'. For example, for the
input shown above and the matrix called 's':
s :
4.000000 0.300000 0.500000
2.000000 4.000000 0.800000
1.000000 0.600000 9.000000
*/
void out2D(char * what, double s[][N], int n)
{
 int i,j;
 double t[N];
    in(s,t,&n);
 printf("%c:\n",*what);
 
 for(i=0;i<n;i++)
 {
  for(j=0;j<n;j++)
  {
   printf("%f\t",s[i][j]); 
  }
  printf("\n"); 
 }
 printf("\n");
}
/*
Prints a vector t which has n elements,
preceded by the name stored in 'what'. For example, for the
input shown above and the matrix called 't':
t :
1.000000
2.000000
3.000000
*/
void out1D(char * what, double t[], int n)
{
 int i;
    double s[N][N], x[N];
    double sx[N];
    mult(s,x,sx,n);
    in(s,t,&n);
    printf("\n%s:\n",what);
    for (i=0;i<n;i++){
        printf("%.2lf",t[i]);
        printf("\n\n");
        }
}
/*
Runs the jacobi iterative solution to S X = T.
The matrix S is given by s and is n x n.
The vector X is given by x, which has n elements.
The vector T is given by t, which has n elements.
The iteration stops if all new elements differ by no more than
EPSILON from the old elements.
*/
void jacobi(double s[][N], double x[], double t[], int n)
{
int i, j, flag = 1, k;
double new_x[N], sum;

while(k<20)
{
 flag=0;
 for(i=0;i<n;i++)
{
 sum=0;
 new_x[i]=t[i];
}
 for(j=0; j<i; j++)
{
 sum -= s[i][j]* x[j];
 
}
 for(j=i+1; j<n; j++)
{
 sum -= s[i][j]* x[j];
}
new_x[i] += sum;
new_x[i]/=s[i][i];

if (fabs(new_x[i]-x[i])>EPSILON)
{
 flag=1;
 x[i]=new_x[i];
 }
k++;}

 

/*
Multiplies an n x n matrix A by a vector X, i.e., an n x 1 matrix.
The resulting vector is called result.
*/
void mult(double a[][N], double x[], double result[], int n)
{

int i, j, sum ;
  for (i = 0 ; i < n ; i++)
  {
    for (j = 0 ; j< n ; j++)
   {
      sum = 0 ;
      
    sum = sum + a[i][j] * x[i] ;
      
    result[i] = sum ;
   }
  }
}

/*
Checks if two vectors are 'close', meaning that each pair of
corresponding elements differ by no more than EPSILON.
It returns a string "Jacobi check fails" if the vectors are not close
otherwise a string "Jacobi check is OK".
*/
char * check(char * name, double sx[], double t[], int n)
{
int i;
for(i = 0 ; i < n ; i++)
if(fabs(sx[i] - t[i]) > 10 * EPSILON)
return (strcat(name, " check fails"));
return (strcat(name, " check is OK"));
}
}

컴파일시 왜 오류가날까요 ㅠㅠ

아 미치겟습니다 도와주세요 ㅠㅠ

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 뛰어난 운동 신경으로 남자와 싸워도 이길 것 같은 여자 스타는? 운영자 25/11/24 - -
이슈 [디시人터뷰] 충무로가 주목하는 신예, '세계의 주인' 서수빈 운영자 25/11/24 - -
AD 따뜻한 겨울나기! 방한용품 SALE 운영자 25/11/27 - -
309606 블로그 이용자가 줄어들고 있어 [1] 이모군(211.60) 12.04.07 66 0
309605 비쥬얼스튜디오에서 exe 파일 만드는거 어떻게 하죠? [9] EvilDragon갤로그로 이동합니다. 12.04.07 175 0
309604 fscanf 질문 (sll > stack 구현) [5] 돌대가리(218.48) 12.04.07 56 0
309603 나는씨발 기계에 대해서 너무 이해가 안된다. [9] 공대생(121.64) 12.04.07 173 0
309602 씨언어 고수님들!리스트 주석도와주세요^^ [4] 김씽(175.223) 12.04.07 85 0
309599 아 우리과에 프갤러 왜이렇게 많아 ㅡㅡ [1] 공학적닭튀김갤로그로 이동합니다. 12.04.07 127 0
309598 횽들 나 좀 살려줰 [2] 생물학(165.194) 12.04.07 55 0
309597 날씨좋다.. 중간점검갤로그로 이동합니다. 12.04.07 27 0
309596 미치겟엉 [2] 삐트리(175.200) 12.04.07 36 0
309595 생물학 지금 내옆에 앉아있음 [4] elwlwlwk갤로그로 이동합니다. 12.04.07 101 0
309594 유명하고 잘 알려진 암호화방식엔 어떤게있나요?? [2] cyber갤로그로 이동합니다. 12.04.07 80 0
309592 정렬된거 합을 정렬하려하는데 O(n^2)만에 됨? [6] ㅁㄴㅇㄹ(125.128) 12.04.07 68 0
309591 숲속의 레스토랑 이모군(175.114) 12.04.07 25 0
309590 형들 이거 10초내로 줄일수있는방법 없을까 [6] 찌르매미(122.203) 12.04.07 107 0
309589 덕후냄새..ㅉㅉ [5] Rei@디씨갤로그로 이동합니다. 12.04.07 117 0
309588 엑세스로 데이터 베이스 작성할때 이런거도 가능한가요?? 데베베(112.163) 12.04.07 33 0
309587 근데 우리나라 프로그래머들이 그렇게외국프로그래머보다 우월하냐??? [8] 에이시아(203.90) 12.04.07 396 0
309586 자짤을 만들었다는게 [1] 생물학(165.194) 12.04.07 39 0
309585 유닉스에서 C언어 짜려구 하는데요 유닉스(119.71) 12.04.07 53 0
309584 c++ 클래스에대해 질문이 있습니다!!! [2] 하양(221.159) 12.04.07 47 0
309583 이번주 로또당첨번호 뽑는 간단 프로그램인데......말을 안듣네.자바스크 [1] 로또로(218.39) 12.04.07 72 0
309581 형들 서울쪽 학원점 추천해쥬여 CaTchingFire갤로그로 이동합니다. 12.04.07 45 0
309579 오브젝트 파스칼이랑 pro*c 써보신분? [2] ㅇㅇ(210.113) 12.04.07 47 0
309578 이클립스 질문 좀 ; ㅇㅇ(124.49) 12.04.07 30 0
309577 어휴 자짤에서 덕내가 풀풀 풍기네요 [1] DeCoY갤로그로 이동합니다. 12.04.07 72 0
309574 로직 잘짜려면 어떻게 해야되요? [4] ㅇㅇ(210.113) 12.04.07 97 0
309573 아웅 이 새벽에 왜 시키지도 않은 일을 하고 있을까-_- [1] 중달(175.116) 12.04.07 43 0
309572 자야겠다 [2] System32갤로그로 이동합니다. 12.04.07 60 0
309571 덕후짤 [5] 좆뉴비(175.205) 12.04.07 123 0
309570 처음으로 어셈 코드를 보았음 [3] 미쳤dot갤로그로 이동합니다. 12.04.07 119 0
309569 프로그래밍 잘가르치고 못가르치고가 있음? [2] Prographer갤로그로 이동합니다. 12.04.07 91 0
309568 살아계신 성님들 계신가..나도 자짤 만들고싶다. [1] Prographer갤로그로 이동합니다. 12.04.07 40 0
309567 근데 성님들... 지금 한 두분정도 남아계신거 같은데 걍 진로 질문좀.. [16] 좆뉴비(175.205) 12.04.07 170 0
309566 나도 슬슬 자짤을 바꾸고 싶은데... [4] 땡칠도사갤로그로 이동합니다. 12.04.07 80 0
309565 새로운 자짤을 만들어봄 [1] System32갤로그로 이동합니다. 12.04.07 73 0
309563 어제 만들던 테트리스 땡칠도사갤로그로 이동합니다. 12.04.07 99 0
309562 내삶의 활력소 [3] System32갤로그로 이동합니다. 12.04.07 89 0
309561 뉴비냄세 쩌는듯 - ㅅ-) [4] 땡칠도사갤로그로 이동합니다. 12.04.07 98 0
309560 번역본 보면 뭔말인지 모르는게 한두개가아님 [4] ㅡㅡ;(211.117) 12.04.07 169 0
309559 요즘 학교에서 프로그래밍 수업 듣기는 하는데 뭘 하는지 모르겠어요..헬프 [6] 질문좀요(14.32) 12.04.07 145 0
309558 ㅜ.ㅠ DMW갤로그로 이동합니다. 12.04.07 21 0
309557 버스커버스커 음악 싸이 배경으로 깔려고 하는데 이게 안되 [2] 1(220.117) 12.04.07 35 0
309555 c++ 클래스에대해 질문이 있습니다!!! [1] 하양(221.159) 12.04.07 54 0
309552 프로그래밍 처음 입문하는 사람이 볼 만한 책 어떤게 있을까? [3] submarine갤로그로 이동합니다. 12.04.07 130 0
309549 헐 lol 들럿갤로그로 이동합니다. 12.04.06 34 0
309544 진짜 간단한 소스 질문좀 부탁해요 성님들 제발제발 !!!! [37] 학생1(143.238) 12.04.06 145 0
309541 헉허헉ㅎㄱ헉허 형들 나 급함. ㄴㅇㄴㅇ(112.170) 12.04.06 31 0
309540 형님들 워크숍가면 뭐하고 놀아야되죠? [1] Html갤로그로 이동합니다. 12.04.06 52 0
309534 회사에서 교육받았던 자료 안가져왔네.. -_- (210.113) 12.04.06 22 0
309533 c언어 이제부터 공부하려고 하는데요 [2] 락쿼즈갤로그로 이동합니다. 12.04.06 65 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2