Advertisement
Guest User

Untitled

a guest
Feb 14th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 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. using System.Numerics;
  7.  
  8.  
  9. namespace ConsoleApplication1
  10. {
  11.     class Program
  12.     {
  13.        
  14.        
  15.  
  16.         static double fun(double A, double B, double C, double D, double x)
  17.         {
  18.             return A * x + B*Math.Sqrt(x*x*x) - C * Math.Exp(-x / 50) - D;
  19.         }
  20.  
  21.         static double czek(double A, double B, double C, double D)
  22.         {
  23.             double a = 0;
  24.             double b = 100;
  25.             double xMid = 1;
  26.             double fmid;
  27.  
  28.             double check = 1;
  29.  
  30.             while (check != 0)
  31.             {
  32.                 xMid = (a + b) / 2.0;
  33.                 fmid = fun(A, B, C, D, xMid);
  34.                 if (fmid < 0) a = xMid;
  35.                 else b = xMid;
  36.                 check = (Int64)(fmid * 100000000);
  37.             }
  38.  
  39.            
  40.             return xMid;
  41.         }
  42.  
  43.         static void Main(string[] args)
  44.         {
  45.             double test = czek(0.59912051,0.64030348,263.33721367,387.92069617);
  46.             double ShouldBe = 73.595368554162;
  47.  
  48.             Console.Read();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement