Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace lab1
- {
- class Program
- {
- /* Заданное k */
- public static double f2(double x, int km)
- {
- double k=0.0, S = 0.0, a = 1.0, y;
- S = S + a;
- while (k <= km)
- {
- y = ((2 * k + 3) / (2 * k + 1)) * ((x * x) / (k + 1));
- a = a * y;
- S += a;
- k++;
- }
- return S;
- }
- /* Заданнная точность */
- public static double f3(double x, double eps)
- {
- double k = 0, S = 0.0, a = 1.0, y;
- S = S + a;
- while (Math.Abs(a) >= eps)
- {
- y = ((2 * k + 3) / (2 * k + 1)) * ((x * x) / (k + 1));
- a = a * y;
- S += a;
- k++;
- }
- return S;
- }
- /*Для "точного" значения*/
- public static double f1(double x)
- {
- return (1 + 2 * x * x) * Math.Exp(x * x); ;
- }
- /* Главная программа*/
- public static void Main(String[] args)
- {
- System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); //изменение языка и региональных параметров текущего потока
- Console.Write("Введите значение k = ");
- int ksum = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите значение eps = ");
- double eps = Convert.ToDouble(Console.ReadLine());
- double a = 0.0, // begin
- b = 1.0, // end
- x; // текущее значение
- int n = 10; // количество точек x
- double y1, y2, y3, h, ep1, ep2;
- h = (b - a) / (double)n;
- Console.WriteLine("Вычисление функции");
- Console.WriteLine("| x | y | SN | SE | погр_SN | погр_SE |");
- Console.WriteLine("|_________|___________|___________|___________|_________|_________|");
- x = a;
- for (int i = 0; i < n; i++)
- {
- y1 = f1(x);
- y2 = f2(x, ksum);
- y3 = f3(x, eps);
- ep1 = (Math.Abs((y2 - y1) / y1)) * 100;
- ep2 = (Math.Abs((y3 - y1) / y1)) * 100;
- string str1 = String.Format("{0:f1}", x);
- string str2 = String.Format("{0:f3}", y1);
- string str3 = String.Format("{0:f3}", y2);
- string str4 = String.Format("{0:f3}", y3);
- string str5 = String.Format("{0:P2}", ep1);
- string str6 = String.Format("{0:P2}", ep2);
- Console.Write("| ");
- Console.Write(str1); //x
- Console.Write(" | ");
- Console.Write(str2); //y
- Console.Write(" | ");
- Console.Write(str3); //SN
- Console.Write(" | ");
- Console.Write(str4); //SE
- Console.Write(" | ");
- Console.Write(str5); //pogr SN
- Console.Write(" | ");
- Console.Write(str6); //pogr SE
- Console.Write(" | ");
- Console.WriteLine();
- x = x + h;
- }
- Console.ReadKey(); // System.Pause C#
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement