Advertisement
mlmisha

NM3 0

May 15th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ЧМ1
  4. {
  5.     public class function
  6.     {
  7.         public int x;
  8.         public double y;
  9.         public function(int a, double b)
  10.         {
  11.             x = a;
  12.             y = b;
  13.         }
  14.     }
  15.     class MainClass
  16.     {
  17.         public static double Sqinter(function [] a, int b)
  18.         {
  19.             double Yo = a[0].y + (a[0].y - a[1].y) * (b - a[0].x) / (a[0].x - a[1].x) + (a[0].y - a[1].y) * (b - a[1].x) * (b - a[0].x) / ((a[0].x - a[1].x) * (a[0].x - a[2].x)) - (a[1].y - a[2].y) * (b - a[1].x) * (b - a[0].x) / ((a[1].x-a[2].x) * (a[0].x-a[2].x));
  20.             return Yo;
  21.         }
  22.         public static void Main(string[] args)
  23.         {
  24.             int[] X = new int[11] {5,10,15,20,25,30,40,50,60,70,80};
  25.             double[] Y = new double[11] {43.7,48,51,53,56.1,58.2,62.5,67,70.8,74.2,77};
  26.             double[] y = new double[3];
  27.             double[] y1 = new double[3];
  28.             int[] x = new int[3] { 13, 31, 65 };
  29.             int[] ind = new int[3];
  30.             function [] xi = new function [3];
  31.             Console.WriteLine("Проведем контроль следующих точек: ");
  32.             for (int i = 0; i < 3; i++)
  33.             {
  34.                 Console.WriteLine("{0}. X = {1}", i + 1, x[i]);
  35.             }
  36.             for (int i = 0; i < 3; i++)
  37.             {
  38.                 for (int r = 0; r < 11; r++)
  39.                 {
  40.                     if (x[i] < X[r])
  41.                     {
  42.                         ind[i] = r;
  43.                         break;
  44.                     }
  45.                 }
  46.             }
  47.             int arg = 0;
  48.             int lok = 0;
  49.             int min = 0;
  50.             Console.WriteLine("Вычисление ближайших значений аргумента");
  51.             for (int i = 0; i < 3; i++)
  52.             {
  53.                 arg = 0;
  54.                 lok = 0;
  55.                 min = 1;
  56.                 while (arg < 3)
  57.                 {
  58.                     if (Math.Abs(x[i] - X[ind[i] + lok]) < Math.Abs(x[i] - X[ind[i] - min]))
  59.                     {
  60.                         xi[arg] = new function (X[ind[i] + lok],Y[ind[i]+lok]);
  61.                         lok++;
  62.                     }
  63.                     else
  64.                     {
  65.                         xi[arg] = new function(X[ind[i] - min],Y[ind[i]-min]);
  66.                         min++;
  67.                     }
  68.                     arg++;
  69.                 }
  70.                 Console.WriteLine("Ближайшие к точке X = {0}:", x[i]);
  71.                 for (int r = 0; r < 3; r++)
  72.                 {
  73.                     Console.WriteLine("{0}. {1}", r + 1, xi[r].x);
  74.                 }
  75.                 //рассчет значения функции в точке
  76.                 y[i] = Sqinter(xi, x[i]);
  77.             }
  78.             Console.WriteLine();
  79.             Console.WriteLine("Итог: ");
  80.             Console.WriteLine();
  81.             for (int i = 0; i < 3; i++)
  82.             {
  83.                 Console.WriteLine("X = {0}  Y = {1:f2}", x[i], y[i]);
  84.             }
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement