Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- /*
- Metody Numeryczne zadanie POCH
- Przygotował: Dawid Grzeszuk
- Kierunek: Informatyka 3 semestr
- Środowisko: Visual Studio 2015
- Język programowania: C#
- */
- namespace POCH
- {
- public static class MathFunctions
- {
- public static readonly double h = 1e-3;
- public static readonly double x0 = 1;
- public static readonly double t0 = 1;
- public static readonly int i = 0;
- public static double f(double x) => Math.Exp(-0.5*x)*Math.Sin(5*Math.PI*x);
- public static double Xi(int i) => x0 + i * h;
- }
- public static class RSP
- {
- public static double RSPFunkcja1(int i) => (-MathFunctions.f(MathFunctions.Xi(i + 2)) + 4 * MathFunctions.f(MathFunctions.Xi(i + 1)) - 3 * MathFunctions.f(MathFunctions.Xi(i))) / (2 * MathFunctions.h);
- public static double RSPFunkcja2(int i) => (-MathFunctions.f(MathFunctions.Xi(i + 3)) + 4 * MathFunctions.f(MathFunctions.Xi(i + 2)) - 5 * MathFunctions.f(MathFunctions.Xi(i + 1)) + 2 * MathFunctions.f(MathFunctions.Xi(i))) / (MathFunctions.h * MathFunctions.h);
- public static double RSPFunkcja3(int i) => (-3 * MathFunctions.f(MathFunctions.Xi(i + 4)) + 14 * MathFunctions.f(MathFunctions.Xi(i + 3)) - 24 * MathFunctions.f(MathFunctions.Xi(i + 2)) + 18 * MathFunctions.f(MathFunctions.Xi(i + 1)) - 5 * MathFunctions.f(MathFunctions.Xi(i))) / (2 * Math.Pow(MathFunctions.h, 3));
- }
- public static class RST
- {
- public static double RSTFunkcja1(int i) => (3 * MathFunctions.f(MathFunctions.Xi(i)) - 4 * MathFunctions.f(MathFunctions.Xi(i - 1)) + MathFunctions.f(MathFunctions.Xi(i - 2))) / (2 * MathFunctions.h);
- public static double RSTFunkcja2(int i) => (2 * MathFunctions.f(MathFunctions.Xi(i)) - 5 * MathFunctions.f(MathFunctions.Xi(i - 1)) + 4 * MathFunctions.f(MathFunctions.Xi(i - 2)) - MathFunctions.f(MathFunctions.Xi(i - 3))) / (MathFunctions.h * MathFunctions.h);
- public static double RSTFunkcja3(int i) => (5 * MathFunctions.f(MathFunctions.Xi(i)) - 18 * MathFunctions.f(MathFunctions.Xi(i - 1)) + 24 * MathFunctions.f(MathFunctions.Xi(i - 2)) - 14 * MathFunctions.f(MathFunctions.Xi(i - 3)) + 3 * MathFunctions.f(MathFunctions.Xi(i - 4))) / (2 * Math.Pow(MathFunctions.h, 3));
- }
- public static class RSC
- {
- public static double RSCFunkcja1(int i) => (MathFunctions.f(MathFunctions.Xi(i + 1)) - MathFunctions.f(MathFunctions.Xi(i - 1))) / (2 * MathFunctions.h);
- public static double RSCFunkcja2(int i) => (MathFunctions.f(MathFunctions.Xi(i + 1)) - 2 * MathFunctions.f(MathFunctions.Xi(i)) + MathFunctions.f(MathFunctions.Xi(i - 1))) / (MathFunctions.h * MathFunctions.h);
- public static double RSCFunkcja3(int i) => (MathFunctions.f(MathFunctions.Xi(i + 2)) - 2 * MathFunctions.f(MathFunctions.Xi(i + 1)) + 2 * MathFunctions.f(MathFunctions.Xi(i - 1)) - MathFunctions.f(MathFunctions.Xi(i - 2))) / (2 * Math.Pow(MathFunctions.h, 3));
- }
- class Program
- {
- static void Main(string[] args)
- {
- #region result tables
- List<double>[] results = new List<double>[3];
- #endregion
- #region execute and show rsp
- results[0] = new List<double>();
- Console.WriteLine("RSP results: ");
- for(int x=0;x<3;x++)
- {
- switch(x)
- {
- case 0:
- results[0].Add(RSP.RSPFunkcja1(MathFunctions.i));
- Console.WriteLine($"function {x + 1}: {results[0][0]}");
- break;
- case 1:
- results[0].Add(RSP.RSPFunkcja2(MathFunctions.i));
- Console.WriteLine($"function {x + 1}: {results[0][1]}");
- break;
- case 2:
- results[0].Add(RSP.RSPFunkcja3(MathFunctions.i));
- Console.WriteLine($"function {x + 1}: {results[0][2]}");
- break;
- }
- }
- #endregion
- #region execute and show rst
- results[1] = new List<double>();
- Console.WriteLine("\nRST results: ");
- for (int x = 0; x < 3; x++)
- {
- switch(x)
- {
- case 0:
- results[1].Add(RST.RSTFunkcja1(MathFunctions.i));
- Console.WriteLine($"function {x + 1}: {results[1][0]}");
- break;
- case 1:
- results[1].Add(RST.RSTFunkcja2(MathFunctions.i));
- Console.WriteLine($"function {x + 1}: {results[1][1]}");
- break;
- case 2:
- results[1].Add(RST.RSTFunkcja3(MathFunctions.i));
- Console.WriteLine($"function {x + 1}: {results[1][2]}");
- break;
- }
- }
- #endregion
- #region execute and show rsc
- results[2] = new List<double>();
- Console.WriteLine("\nRSC results: ");
- for (int x = 0; x < 3; x++)
- {
- switch (x)
- {
- case 0:
- results[2].Add(RSC.RSCFunkcja1(MathFunctions.i));
- Console.WriteLine($"function {x + 1}: {results[2][0]}");
- break;
- case 1:
- results[2].Add(RSC.RSCFunkcja2(MathFunctions.i));
- Console.WriteLine($"function {x + 1}: {results[2][1]}");
- break;
- case 2:
- results[2].Add(RSC.RSCFunkcja3(MathFunctions.i));
- Console.WriteLine($"function {x + 1}: {results[2][2]}");
- break;
- }
- }
- #endregion
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement