Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATHCAD program to solve systems of linear equations using the iterative

ID: 2971217 • Letter: W

Question

Write a MATHCAD program to solve systems of linear equations using the iterative Jacobi Method. The method is explained in the file named "Jacobi Method", pay attention to the convergence condition. The program should be able to solve systems with n equations and n unknowns (nxn), given that coefficient matrix is diagonally dominant. Check your program with the following systems of equations ( picture attached).

System of Equations to check with..



My teacher's notes on "iterative solutions".

I posted them just in case they were helpful.


[Ca] middot x = ba (ga are guessing values for x) [Cb] middot x = bb (gb are guessing values for x) THIS METHODS CONSIST OF A TRIAL THAT MAY BE MUCH FASTER METHODS, BECAUSE INVOLVE LESS COMPUTATION, LET'S THE SAME 4 times 4 EXAMPLE AMD WRITE IT IN THE FOLLOWING FORM: A 11 X 1 + A 12 X 2 + A 13 X 3 + A 14 X 4 = b 1 A 21 X 1 + A 22 X 2 + A 23 X 3 + A 24 X 4 = b 2 A 31 X 1 + A 32 X 2 + A 33 X 3 + A 34 X 4 = b 3 A 41 X 1 + A 42 X 2 + A 43 X 3 + A 44 X 4 = b 4 WE CAN REWRITE THESE EQUATIONS AS FOLLOWS : X 1 = 1/A 11 [b 1 - A 12 X 1 - A 13 X 3 - A 14 X 4] X 2 = 1/A 22 [b 2 - A 21 X 1 - A 23 X 3 - A 24 X 4] X 3 = 1/A 33 [b 3 - A 31 X 1 - A 32 X 2 - A 34 X 4] X 4 = 1/A 44 [b 4 - A 41 X 1 - A 42 X 2 - A 43 X 3] GENERALIZING : X i = 1/A ii [b i - A ij X J] i = 1, 2, ...n THIS METHOD AN INITIAL TO START THE PROCEDURE X l (0) FOR i = 1, 2, ...n, SO THEN THE METHOD USE THE EQUATION ABOVE TO OBTAIN AN UPDATED SOLUATION VECTOR X i (1), WHICH IS USED FOR THE NEXT ITERATION STEP. IN GENERAL : X i = 1/A ii [b i - A ij X j (K - 1)] THE METHOD IS APPLIED UNTIL THE DIFFERNCE BETWEEN THE PREVIOUS AND UPDATED VALUES BECOME SMALL (CONVERGENCE) |X i (K + 1)- X i (K)|

Explanation / Answer

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<stdlib.h>

void main()



{

float a[20][20],x[20],e,big,temp,relerror,sum;


int n,i,j,maxit,itr;


char ch;


clrscr();


printf(" ENTER THE SIZE OF THE EQUATION :: ");


scanf("%d",&n);


for(i=1;i<=n;i++)


{


printf(" Enter the coefficints of equation %d and RHS ",i);


for(j=1;j<=n+1;j++)


scanf("%f",&a[i][j]);


}


printf(" Enter relative error and number of iteration :: ");


scanf("%f%d",&e,&maxit);


for(i=1;i<=n;i++)


x[i]=0;


for(itr=1;itr<=maxit;itr++)


{


big=0;


for(i=1;i<=n;i++)


{


sum=0;


for(j=1;j<=n;j++)


{


if(i!=j


)


sum=sum+a[i][j]*x[j];


}


temp=(a[i][n+1]-sum)/a[i][i];


relerror=fabs((x[i]-temp)/temp);


if(relerror>big)


big=relerror;


x[i]=temp;


}


if(big<=e)


{


printf("Converges to a solution in %d iterations ",itr);


for(i=1;i<=n;i++)


printf(" %.4f ",x[i]);


getch();


exit(1);


}




}


printf("does not converge in %d iteration ",maxit);


getch();


}





this program have an option to choose no of iterations , and relative error

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote