Last active
June 1, 2019 18:11
-
-
Save alldevic/8ab7e3b3f4370694db24b898666cac49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Taylor | |
{ | |
internal class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
double xbegin, xend, dx, eps; | |
try | |
{ | |
xbegin = ReadDouble("Введите Xнач:", 1, 3); | |
xend = ReadDouble("Введите Xкон:", xbegin, 3); | |
dx = ReadDouble("Введите шаг dx:", 0.001, 1); | |
eps = ReadDouble("Введите точность eps:", 0.0000000001, 1); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
Console.WriteLine("Приложение будет закрыто"); | |
Console.ReadKey(); | |
return; | |
} | |
Console.WriteLine(); | |
Console.WriteLine("\t\t\tЗНАЧЕНИЯ ARCCOS(X)\t\t\t"); | |
Console.WriteLine("|\tx\t|\tf(x)\t|\tN\t|\tC#(f(x))\t"); | |
while (xbegin <= xend) | |
{ | |
double prev = Arth(xbegin, 1); | |
double curr = Arth(xbegin, 2); | |
int count = 2; | |
while (Math.Abs(curr - prev) > eps) | |
{ | |
prev = curr; | |
count++; | |
curr = Arth(xbegin, count); | |
} | |
prev = Math.Round(prev, eps.ToString().Length); | |
Console.WriteLine(GetTableRow(xbegin, prev, count - 1)); | |
xbegin += dx; | |
xbegin = Math.Round(xbegin, 15); | |
} | |
} | |
private static double Arth(double x, int n) | |
{ | |
double res = 0; | |
double tmp = 0; | |
for (int i = 0; i < n; i++) | |
{ | |
tmp = 2 * i + 1; | |
res += 1 / (tmp * Math.Pow(x, tmp)); | |
} | |
return res; | |
} | |
public static double ReadDouble(string message, double min, double max) | |
{ | |
Console.WriteLine(message); | |
try | |
{ | |
double res = Convert.ToDouble(Console.ReadLine()); | |
if (res < min || res > max) | |
{ | |
throw new ArgumentOutOfRangeException(); | |
} | |
return res; | |
} | |
catch (FormatException) | |
{ | |
throw new Exception("Введены некорректные данные! Вы ввели не число с плавающей точкой"); | |
} | |
catch (IndexOutOfRangeException) | |
{ | |
string exMessage = string.Format("Введены некорректные данные! Введенное число не лежит на [{0}; {1}]", | |
min, max); | |
throw new Exception(exMessage); | |
} | |
} | |
static string GetTableRow(double x, double fx, double count) | |
{ | |
return string.Format("|\t{0}\t|\t{1}\t|\t{2}\t", x, fx, count); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment