Advertisement
mrAnderson33

Первая лаба вычтех

Oct 6th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace MPI_дз_вычтех_
  7. {
  8.     class Program
  9.     {
  10.         delegate double func(double c);
  11.  
  12.         const double eps = 0.001;
  13.         static void Main(string[] args)
  14.         {
  15.             func f = (x) => 0.5 - Math.Log10(x);
  16.  
  17.             double a = 0.5;
  18.             double b = 2;
  19.  
  20.             double xn = a;
  21.             int counter = 0;
  22.             Console.WriteLine("Первое уравнение МПИ:");
  23.             while(Math.Abs(f(xn)-xn) > eps)
  24.             {
  25.                 xn = f(xn);
  26.                 Console.WriteLine("x{0}={1}",counter++, xn);
  27.             }
  28.  
  29.             Console.WriteLine("x*={0}", xn);
  30.  
  31.              f = (x) => Math.Pow(x, 3) + 0.4 * Math.Pow(x,2) + 0.6 * x - 1.6;
  32.             counter = 0;
  33.             b = 1;
  34.             Console.WriteLine("Второе уравнение МПД:");
  35.             while (Math.Abs(b - a) > eps)
  36.             {
  37.                 xn = (a + b) / 2;
  38.                 Console.WriteLine("x{0}={1}",counter++,xn);
  39.                 if (f(xn) * f(a) < 0) b = xn;
  40.                 else if (f(xn) * f(b) < 0) a = xn;
  41.             }
  42.  
  43.             Console.WriteLine("x*={0}", xn);
  44.             Console.WriteLine("Третье уравнение метод Ньютона:");
  45.            
  46.             counter = 0;
  47.             a = 0;
  48.             xn = a;
  49.  
  50.  
  51.             f = (x) => Math.Asin(2 * x / (1 + Math.Pow(x, 2))) - Math.Exp(-Math.Pow(x, 2));
  52.  
  53.             func df = (x) => 2 * x * Math.Exp(-Math.Pow(x, 2)) + ((2/(Math.Pow(x,2)+1)) - (4*Math.Pow(x,2)/(Math.Pow((Math.Pow(x,2)+1),2))))/(Math.Sqrt(1 - ((4*Math.Pow(x,2)/(Math.Pow((Math.Pow(x,2)+1),2))))));
  54.  
  55.             func xk = (x) => xn - f(xn)/df(xn) ;
  56.  
  57.             while (Math.Abs(xk(xn) - xn) > eps)
  58.             {
  59.                 xn = xk(xn);
  60.                 Console.WriteLine("x{0}={1}", counter++, xn);
  61.             }
  62.  
  63.  
  64.  
  65.            
  66.         }
  67.  
  68.  
  69.    
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement