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;
- namespace Integral
- {
- class Program
- {
- static void Main(string[] args)
- {
- int N = 20;
- double a = 1;
- double b = 2;
- double[] xi = new double[N+1];
- double[] fxi = new double[N + 1];
- double[] rectangle = new double[N + 1];
- double[] trapeze = new double[N + 1];
- int x0 = 0;
- double A = 0;
- double B = 2;
- double dx = (B - A) / N;
- xi = GetXi(xi, dx, x0);
- fxi = GetfXi(xi, a, b);
- rectangle = GetRectangleSolution(fxi, dx);
- trapeze = GetTrapeziumSolution(fxi, dx);
- double sumRectangle = GetSumArray(rectangle);
- double sumTrapeze = GetSumArray(trapeze);
- double calcualtionError = Math.Abs(sumRectangle - sumTrapeze);
- double upperValue = (1 / Math.Pow(a, 3)) * ((a * 2 + b) - 2 * b * Math.Log(Math.Abs(a * 2 + b)) - (Math.Pow(b, 2) / (a * 2 + b)));
- double lowerValue = (1 / Math.Pow(a, 3)) * ((a * 0 + b) - 2 * b * Math.Log(Math.Abs(a * 0 + b)) - (Math.Pow(b, 2) / (a * 0 + b)));
- double exactValue=upperValue - lowerValue;
- ShowResult(xi, fxi, rectangle, trapeze,exactValue);
- Console.ReadKey();
- }
- static double[] GetXi(double[] xi,double dx, int x0)
- {
- for (int i = 0; i < xi.Length; i++)
- xi[i] = x0 + dx * i;
- return xi;
- }
- static double[] GetfXi(double[] xi, double a, double b)
- {
- double[] result = new double[xi.Length];
- for (int i = 0; i < xi.Length; i++)
- result[i] = Math.Pow(xi[i], 2) / Math.Pow((xi[i] * a + b), 2);
- return result;
- }
- static double[] GetRectangleSolution(double[] fxi, double dx)
- {
- double[] result = new double[fxi.Length-1];
- for (int i = 0; i < result.Length; i++)
- result[i] = fxi[i] * dx;
- return result;
- }
- static double GetSumArray(double[] array)
- {
- double result = 0;
- for (int i = 0; i < array.Length; i++)
- result += array[i];
- return result;
- }
- static void ShowArray(double[] array)
- {
- for (int i = 0; i < array.Length; i++)
- Console.WriteLine(" " + array[i]);
- }
- static void ShowResult(double[] xi, double[] fxi, double[] rectangle, double[] trapeze,double exactValue)
- {
- Console.WriteLine("xi\tfxi\trec\ttrape");
- for (int i = 0; i < xi.Length-1; i++)
- Console.WriteLine("{0}\t{1:0.000}\t{2:0.0.000}\t{3:0.000}", xi[i],fxi[i],rectangle[i],trapeze[i]);
- Console.WriteLine();
- Console.WriteLine("Точное значение ={0:0.000}",exactValue);
- }
- static double[] GetTrapeziumSolution(double[] fxi,double dx)
- {
- double[] result = new double[fxi.Length - 1];
- for (int i = 0; i < fxi.Length-1; i++)
- result[i] = (fxi[i] + fxi[i + 1]) / 2 * dx;
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement