Advertisement
kot025

LAB3

Nov 22nd, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication6
  8. {
  9.     class Program
  10.     {
  11.         static double SN (double x)
  12.         {
  13.             double s = 0, el = 1;
  14.             for (int i = 1; i < 41; i++)
  15.             {
  16.                 el *= -(x + 1) * (x + 1) / i;
  17.                 s += el;
  18.             }
  19.             return s;
  20.         }
  21.         static double SE (double x, double y, double eps)
  22.         {
  23.             double el = 1, s = 0;
  24.             int i = 1;
  25.             do
  26.             {
  27.                 el *= (-(x + 1) * (x + 1)) / i;
  28.                 //el = Math.Pow(-1, i)*Math.Pow(x + 1, 2 * i) / i;
  29.                 i++;
  30.                 //Console.Write(s + " " + y);
  31.                 //Console.WriteLine();
  32.                 s += el;
  33.             } while (Math.Abs(el) > eps);  
  34.             return s;
  35.         }
  36.         static void Main(string[] args)
  37.         {
  38.             double step = (-2 + 0.1) / 10;
  39.             double x = -0.1;
  40.             double y;
  41.             double eps = 0.0001;
  42.             for (int i = 1; i < 11; i++)
  43.             {
  44.                 y = Math.Log(1 / (x * x + 2 * x + 2), Math.E);
  45.                 Console.WriteLine("SN = {0:0.000000000} SE = {1:0.000000000} x = {2:0.00}, y = {3:0.000000000}", SN(x), SE(x, y, eps), x, y);
  46.                 x += step;
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement