Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //LAB 3
- //METHODOS GAUSS
- #include <math.h>
- #include <stdio.h>
- double F(const double t)
- {
- return exp(-(t + 3) / 4) + cos(7 * (t + 3) / 4) - 6 / (t - 5);
- }
- main()
- {
- double I2 = (1. * F(0.577350269189626) + 1. * F(-0.577350269189626)) / 2;
- double I3 = (0.888888888888889 * F(0) + 0.555555555555556 * F(0.774596669241483) + 0.555555555555556 * F(-0.774596669241483)) / 2;
- double I5 = (0.568888888888889 * F(0) + 0.478628670499366 * F(0.538469310105683) + 0.478628670499366 * F(-0.538469310105683) + 0.236926885056189 * F(0.906179845938664) + 0.236926885056189 * F(-0.906179845938664)) / 2;
- printf("n=2 apot=%10.8f\nn=3 apot=%10.8f\nn=5 apot=%10.8f\n", I2, I3, I5);
- return 0;
- }
- //METHODOS TRAPEZIOY
- #include <math.h>
- #include <stdio.h>
- double f(const double x)
- {
- return exp(-x / 2) + cos(3.5 * x) - 3 / (x - 4);
- }
- double I(const int n, const double a, const double b)
- {
- int i;
- const double h = (b - a) / n;
- double I = 0;
- for (i = 0; i <= n; ++i) {
- I += (i == 0 || i == n ? f(a + i * h) / 2 : f(a + i * h));
- }
- I *= h;
- return I;
- }
- main()
- {
- double I1 = I(50, 1, 2), I2 = I(100, 1, 2);
- printf("a=%f b=%f\nn=%3d apot=%10.8f\nn=%3d apot=%10.8f\nerror=%f\n", 1., 2., 50, I1, 100, I2, fabs(I1 - I2));
- return 0;
- }
- //METHODOS SIMSON
- #include <math.h>
- #include <stdio.h>
- double f(const double x)
- {
- return exp(-x / 2) + cos(3.5 * x) - 3 / (x - 4);
- }
- double I(const int n, const double a, const double b)
- {
- int i;
- const double h = (b - a) / n;
- double I = 0;
- for (i = 0; i <= n; ++i) {
- if (i == 0 || i == n) {
- I += f(a + i * h);
- } else if (i % 2 == 0) {
- I += 2 * f(a + i * h);
- } else {
- I += 4 * f(a + i * h);
- }
- }
- I *= h / 3;
- return I;
- }
- main()
- {
- double I1 = I(50, 1, 2), I2 = I(100, 1, 2);
- printf("a=%f b=%f\nn=%3d apot=%10.8f\nn=%3d apot=%10.8f\nerror=%.10f\n", 1., 2., 50, I1, 100, I2, fabs(I1 - I2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement