Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ЧМ1
- {
- public class function
- {
- public int x;
- public double y;
- public function(int a, double b)
- {
- x = a;
- y = b;
- }
- }
- class MainClass
- {
- public static double Sqinter(function [] a, int b)
- {
- 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));
- return Yo;
- }
- public static void Main(string[] args)
- {
- int[] X = new int[11] {5,10,15,20,25,30,40,50,60,70,80};
- double[] Y = new double[11] {43.7,48,51,53,56.1,58.2,62.5,67,70.8,74.2,77};
- double[] y = new double[3];
- double[] y1 = new double[3];
- int[] x = new int[3] { 13, 31, 65 };
- int[] ind = new int[3];
- function [] xi = new function [3];
- Console.WriteLine("Проведем контроль следующих точек: ");
- for (int i = 0; i < 3; i++)
- {
- Console.WriteLine("{0}. X = {1}", i + 1, x[i]);
- }
- for (int i = 0; i < 3; i++)
- {
- for (int r = 0; r < 11; r++)
- {
- if (x[i] < X[r])
- {
- ind[i] = r;
- break;
- }
- }
- }
- int arg = 0;
- int lok = 0;
- int min = 0;
- Console.WriteLine("Вычисление ближайших значений аргумента");
- for (int i = 0; i < 3; i++)
- {
- arg = 0;
- lok = 0;
- min = 1;
- while (arg < 3)
- {
- if (Math.Abs(x[i] - X[ind[i] + lok]) < Math.Abs(x[i] - X[ind[i] - min]))
- {
- xi[arg] = new function (X[ind[i] + lok],Y[ind[i]+lok]);
- lok++;
- }
- else
- {
- xi[arg] = new function(X[ind[i] - min],Y[ind[i]-min]);
- min++;
- }
- arg++;
- }
- Console.WriteLine("Ближайшие к точке X = {0}:", x[i]);
- for (int r = 0; r < 3; r++)
- {
- Console.WriteLine("{0}. {1}", r + 1, xi[r].x);
- }
- //рассчет значения функции в точке
- y[i] = Sqinter(xi, x[i]);
- }
- Console.WriteLine();
- Console.WriteLine("Итог: ");
- Console.WriteLine();
- for (int i = 0; i < 3; i++)
- {
- Console.WriteLine("X = {0} Y = {1:f2}", x[i], y[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement