0% found this document useful (0 votes)
7 views14 pages

CBNSTNEWLABFILE

The document contains multiple code snippets and outputs related to numerical methods and error calculations, authored by Mohammad Ali. It includes convergence checks, backward difference tables, and error analysis for approximations of mathematical functions. Each section is labeled with the author's name, section, and roll number.

Uploaded by

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

CBNSTNEWLABFILE

The document contains multiple code snippets and outputs related to numerical methods and error calculations, authored by Mohammad Ali. It includes convergence checks, backward difference tables, and error analysis for approximations of mathematical functions. Each section is labeled with the author's name, section, and roll number.

Uploaded by

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

printf("Solution does not converge within the maximum iterations.

\n");
return 1;
}

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


Output:

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


} else {
printf("\nChange the function, convergence condition not satisfied.");
exit(1);
}

return 0;
}

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


Output :

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


double x2;
int itr = 0;
while (true) {
itr++;
x2 = x1 - (((x1 - x0) / (f(x1) - f(x0))) * f(x1));
printf("\nIteration %d: x = %lf, f(x) = %lf", itr, x2, f(x2));
if (fabs(f(x2)) <= allowed) {
printf("\nThe root is %lf", x2);
break;
} else {
x0 = x1;
x1 = x2;
}
}
return 0;
}

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


Output :

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


for (i = n - 1; i >= 0; i--) {
x[i] = arr[i][n];
for (j = i + 1; j < n; j++) {
x[i] = x[i] - arr[i][j] * x[j];
}
x[i] = x[i] / arr[i][i];
}

printf("\nThe solution is:\n");


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

return 0;
}

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


Output:

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


printf("\nDisplaying the backward difference table:\n\n");
for (int i = 0; i < n; i++) {
printf("%0.2f\t\t", x[i]);
for (int j = 0; j <= i; j++) {
printf("%0.2f\t\t", y[i][j]);
}
printf("\n");
}
float value = 0;
printf("\"Enter the value of x for which you want to calculate y: ");
scanf("%f", &value);

float sum = y[n - 1][0];


float u = (value - x[n - 1]) / (x[1] - x[0]);

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


sum += (u_cal(u, i) * y[n - 1][i]) / fact(i);
}

printf("Value at x = %0.4f is %0.4f\n", value, sum);

return 0;
}

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


Output:

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


Program:

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

int main() {
float tv = 1.0 / 2.0;
float av[] = {0.31, 0.33, 0.34};
int count = sizeof(av) / sizeof(av[0]);
float leastav = FLT_MAX;
float closestValue = 0.0;

for (int i = 0; i < count; i++) {


float absoluteDifference = fabs(av[i] - tv);

if (absoluteDifference < leastav) {


leastav = absoluteDifference;
closestValue = av[i];
}
}
printf("The closest value to %.2f is: %.2f\n", tv, closestValue);
printf("The least absolute difference is: %.6f\n", leastav);
return 0;

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


Output:

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


Program:

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

int main() {

double trueValue = sqrt(2);


double approxValue = 1.415;

double absoluteError = fabs(trueValue - approxValue);


double relativeError = absoluteError / trueValue;
double percentageError = relativeError * 100;

printf("True value of sqrt(2): %.4f\n", trueValue);


printf("Approximate value: %.4f\n", approxValue);
printf("Absolute error: %.4f\n", absoluteError);
printf("Relative error: %.4f\n", relativeError);
printf("Percentage error: %.4f%%\n", percentageError);

return 0;

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36


Output:

NAME: MOHAMMAD ALI SECTION: I1 ROLL NO: 36

You might also like