22
file.org
22
file.org
@@ -22,28 +22,35 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#define EPSILON 0.0000001
|
||||
|
||||
#define f(x) ((352 * x * x * x) - (64 * x * x) + (198 * x) - 36)
|
||||
#define f1(x) ((1056 * x * x) - (128 * x) + 198)
|
||||
|
||||
double newtonRaphson(double x) {
|
||||
double h = f(x) / f1(x);
|
||||
if (f(x) == 0 || fabs(h) < EPSILON)
|
||||
return x;
|
||||
return newtonRaphson(x - h);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Root for f(x) = 352x^3 - 64x^2 + 198x - 36 is %lf",
|
||||
newtonRaphson(-4));
|
||||
}
|
||||
#+end_src
|
||||
|
||||
* Program for nding roots of f(x) = 0 using bisection method
|
||||
#+LATEX: \clearpage
|
||||
|
||||
* Program for finding roots of f(x) = 0 using bisection method
|
||||
#+ATTR_LATEX: :options frame=single,breaklines=true
|
||||
#+begin_src C :tangle 2.c :results output :exports both :wrap src text
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define EPSILON 0.0000001
|
||||
#define f(x) ((352 * x * x * x) - (64 * x * x) + (198 * x) - 36)
|
||||
|
||||
double bisection(double a, double b) {
|
||||
double x;
|
||||
if (f(a) * f(b) > 0) {
|
||||
@@ -58,6 +65,7 @@ double bisection(double a, double b) {
|
||||
return bisection(x, b);
|
||||
return bisection(a, x);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Root for f(x) = 352x^3 - 64x^2 + 198x - 36 is %lf",
|
||||
bisection(1.6, -4));
|
||||
@@ -72,7 +80,9 @@ int main() {
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#define EPSILON 0.0000001
|
||||
|
||||
#define f(x) ((352 * x * x * x) - (64 * x * x) + (198 * x) - 36)
|
||||
|
||||
double secant(double a, double b) {
|
||||
double x1;
|
||||
x1 = (a * f(b) - b * f(a)) / (f(b) - f(a));
|
||||
@@ -80,6 +90,7 @@ double secant(double a, double b) {
|
||||
return x1;
|
||||
return secant(b, x1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Root for f(x) = 352x^3 - 64x^2 + 198x - 36 is %lf", secant(1.6, -4));
|
||||
}
|
||||
@@ -206,6 +217,8 @@ Enter interpolation point x: 999
|
||||
Interpolated value for 999.000000 is 9525764925.000002.
|
||||
#+end_src
|
||||
|
||||
#+LATEX: \clearpage
|
||||
|
||||
* Program for solving numerical integration by trapezoidal method.
|
||||
#+ATTR_LATEX: :options frame=single,breaklines=true
|
||||
#+begin_src C :tangle 6.c :results output :exports both :wrap src text
|
||||
@@ -234,6 +247,8 @@ int main() {
|
||||
}
|
||||
#+end_src
|
||||
|
||||
#+LATEX: \clearpage
|
||||
|
||||
* Program for solving numerical integration by Simpson's 1/3 rule.
|
||||
#+ATTR_LATEX: :options frame=single,breaklines=true
|
||||
#+begin_src C :tangle 7.c :results output :exports both :wrap src text
|
||||
@@ -351,14 +366,18 @@ int main() {
|
||||
for (int j = 0; j < ORDER; j++)
|
||||
printf("%lf ", inv[i][j + ORDER]);
|
||||
printf("\n");
|
||||
|
||||
free(inv[i]);
|
||||
free(matrix[i]);
|
||||
}
|
||||
|
||||
free(inv);
|
||||
free(matrix);
|
||||
}
|
||||
#+end_src
|
||||
|
||||
#+LATEX: \clearpage
|
||||
|
||||
* Program for finding eigen values using power method.
|
||||
#+ATTR_LATEX: :options frame=single,breaklines=true
|
||||
#+begin_src C :tangle 10.c :results output :exports both :wrap src text
|
||||
@@ -421,6 +440,7 @@ int main() {
|
||||
printf("%lf ", egn[i]);
|
||||
free(matrix[i]);
|
||||
}
|
||||
|
||||
free(egn);
|
||||
free(matrix);
|
||||
}
|
||||
|
Reference in New Issue
Block a user