Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Integration2._1 {
- class Program {
- static float f(float x) {
- return 1 / MathF.Pow(MathF.Cosh(x), 2);
- // return MathF.Sqrt(x + 1);
- }
- static float t(float x, float min, float max) {
- return (max + min) / 2 + (max - min) / 2 *x ;
- }
- static void Cheb(int m, float min, float max) {
- float[] x3 = { -0.707107f, 0, 0.707107f };
- float[] x2 = { -0.577350f, 0.577350f };
- float[] x5 = { -0.11547f, -0.11547f, 0, 0.11547f, 0.11547f, };
- float[] x10 = { -0.0577350f, -0.0577350f, -0.0577350f, -0.0577350f, -0.0577350f, 0.0577350f, 0.0577350f, 0.0577350f, 0.0577350f, 0.577350f };
- float integral = 0;
- int count = 0;
- if (m == 2) {
- for (int j = 0; j < m; j++) {
- integral += f(t(x2[j], min, max));
- }
- }
- else if(m == 3) {
- for (int j = 0; j < m; j++) {
- integral += f(t(x3[j], min, max));
- }
- }
- else if(m == 5) {
- for (int j = 0; j < m; j++) {
- integral += f(t(x5[j], min, max));
- }
- }
- else if (m == 10) {
- for (int j = 0; j < m; j++) {
- integral += f(t(x10[j], min, max));
- }
- }
- else if (m == 100) {
- float strange = 0.577350f / 100;
- for (int j = 0; j < m; j++) {
- if (j <= 49)
- strange *= -1;
- integral += f(t(strange, min, max));
- }
- }
- integral *= (max-min) / m;
- Console.WriteLine(integral);
- }
- static void Gauss(int m, float min, float max) {
- float[] x2 = { -0.577350f, 0.577350f };
- float[] x3 = { -0.77459667f, 0, 0.77459667f };
- float[] Aj = { 5 / 9f, 8 / 9f, 5 / 9f };
- float integral = 0;
- if (m == 2) {
- for (int j = 0; j < m; j++) {
- integral += f(t(x2[j], min, max));
- }
- }
- else if (m == 3) {
- for (int j = 0; j < m; j++) {
- integral += Aj[j] * f(t(x3[j], min, max));
- }
- }
- integral *= (max - min) / 2;
- Console.WriteLine(integral);
- }
- static void Main(string[] args) {
- //float min = 1, max = 3;
- float min = MathF.Log(2), max = MathF.Log(3);
- Cheb(2, min, max);
- }
- }
- }
Add Comment
Please, Sign In to add comment