My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
Simultaneous Equations-Gauss Jacobi Iteration
Posted Date:
Total Responses: 0
Posted By: Vikram Narayan C Member Level: Silver Points/Cash: 3
|
#include //stdio.h #include //conio.h #include //math.h #include //stdlib.h #define maxy 10 float a[maxy][maxy]={0.0},b[maxy][1]={0},x[maxy]={0}; float i,j,k,l,xt[maxy]={0},t,n; int flag=0,dd=0,row,vikki=0; int diagonal() { int i,j,t; for(i=0;i { t=0; for(j=0;j { if(j==i) continue; t=t+abs(a[i][j]); } if(abs(a[i][i])<=t) { row = i; return 0; } } return(1); } void swap() { int i=0,j=0,t=0; for(i=0;i { if(i<=row) continue; vikki++; for(j=0;j { t=a[row][j]; a[row][j]=a[i][j]; a[i][j]=t; t=b[row][0]; b[row][0]=b[i][0]; b[i][0]=t; } } } void main() { clrscr(); printf("\nEnter the number of equations:"); scanf("%f",&n); printf("Enter the coefficient matrix :"); for(i=0;i { for(j=0;j { scanf("%f",&a[i][j]); } } printf("\nEnter the constant matrix:"); for(i=0;i { scanf("%f",&b[i][0]); } printf("\nThe given matrix is:\n"); for(i=0;i { for(j=0;j { printf("%0.2f ",a[i][j]); } printf("\n"); } dd=diagonal(); /* Diagonally Dominant */ while(dd==0) { swap(); dd=diagonal(); if(dd==1) break; if(vikki>n+1) break; if(n>2) vikki=0; } if(vikki>=n+1) { printf("\nThe system is not diagonally dominant:"); printf("\nThe convergance is not assured"); getch(); exit(0); } for(k=0;k<100;k++) { for(i=0;i { t=0; for(j=0;j { if(j==i) continue; t = t + a[i][j]*xt[j]; } x[i]= (b[i][0] - t) / a[i][i]; } for(i=0;i { if((int)(xt[i]*1000000)!=(int)(x[i]*1000000)) { flag=0; break; } flag=1; } for(i=0;i { xt[i] = x[i]; } if(flag==1) { break; } }
printf("\nThe diagonally dominant matrix:\n"); for(i=0;i { for(j=0;j { printf("%0.2f ",a[i][j]); } printf("\n"); }
printf("\nThe Solution is: "); for(i=0;i { printf("%f\t",x[i]); } printf("\nThe number of steps : %f",k+1); getch(); }
|
Project Feedbacks
|
No feedbacks found. Be the first to respond and make money from revenue sharing program.
|
|
|
| Post Feedback |
|
|
You must Sign In to post a feedback.
|
|
|
|
|
|