0% found this document useful (0 votes)
21 views3 pages

NM Lab789

Nmlabb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

NM Lab789

Nmlabb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

//gauss seidel lab 7

#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x,float y, float z)
{
return((11.19-y+z)/10);
}
float s(float x,float y,float z)
{
return(28.80-z-x)/10;
}
float t(float x,float y,float z)
{
return(35.61+x-y)/10;
}
int main(){
float x0,y0,z0,x1=0,y1=0,z1=0,tempx,tempy,tempz,acc=0.001;
int iteration=0;
printf("enter the initial guesses:\n");
scanf("%f%f%f",&x0,&y0,&z0);
do{
tempx=x1;tempy=y1;tempz=z1;
x1=f(x0,y0,z0);y1=s(x0,y0,z0);z1=t(x0,y0,z0);
iteration++;
x0=x1;y0=y1;z0=z1;
}
while(fabs(tempx-x1)>acc&&fabs(tempy-y1)>acc&&fabs(tempz-z1)>acc);
printf("\n\nfinally,\n");
printf("x=%f\ny=%f\nz=%f\n",x1,y1,z1);
printf("iteration=%d",iteration);
return 0;

//gauss jacobi lab 8


#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x,float y, float z)
{
return((17-y+2*z)/20);
}
float s(float x,float y,float z)
{
return(-18+z-3*x)/20;
}
float t(float x,float y,float z)
{
return(25-2*x+3*y)/20;
}
int main(){
float x0,y0,z0,x1=0,y1=0,z1=0,tempx,tempy,tempz,acc=0.0001;
int iteration=0;
printf("enter the initial guesses:\n");
scanf("%f%f%f",&x0,&y0,&z0);
do{
tempx=x1;tempy=y1;tempz=z1;
x1=f(x0,y0,z0);y1=s(x0,y0,z0);z1=t(x1,y1,z0);
iteration++;
x0=x1;y0=y1;z0=z1;
}
while(fabs(tempx-x1)>acc&&fabs(tempy-y1)>acc&&fabs(tempz-z1)>acc);
printf("\n\nfinally,\n");
printf("x=%f\ny=%f\nz=%f\n",x1,y1,z1);
printf("iteration=%d",iteration);
return 0;

//power series lab 9


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

int main(){
int i, j, n;
float A[40][40], x[40], z[40], e[40], zmax, emax;

printf("\nEnter the order of the matrix: ");


scanf("%d", &n);

printf("\nEnter the matrix elements row-wise\n");


for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
printf("A[%d][%d] = ", i, j);
scanf("%f", &A[i][j]);
}
}

printf("\nEnter the column vector\n");


for(i = 1; i <= n; i++){
printf("x[%d] = ", i);
scanf("%f", &x[i]);
}

do{
for(i = 1; i <= n; i++){
z[i] = 0;
for(j = 1; j <= n; j++){
z[i] = z[i] + A[i][j] * x[j];
}
}

zmax = fabs(z[1]);

for(i = 2; i <= n; i++){


if(fabs(z[i]) > zmax)
zmax = fabs(z[i]);
}

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


z[i] = z[i] / zmax;
}

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


e[i] = 0;
e[i] = fabs(fabs(z[i]) - fabs(x[i]));
}

emax = e[1];

for(i = 2; i <= n; i++){


if(e[i] > emax)
emax = e[i];
}

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


x[i] = z[i];
}
} while(emax > 0.001);

printf("\nRequired eigenvalue is %f", zmax);

printf("\nRequired eigenvector is:\n");


for(i = 1; i <= n; i++){
printf("%f\t", z[i]);
}

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy