Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4.  
  5. namespace Zadanie7
  6. {
  7.     class Program
  8.     {
  9.         const int size = 10;
  10.         static double rozdzielczosc = 0.01;
  11.         //static double[] wyniki = new double[size];
  12.         static List<double> wyniki = new List<double>();
  13.         static double poprzednia, nastepna, maximum;
  14.         static Thread[] wątki = new Thread[size];
  15.         static int licznik=0;
  16.         static double funkcja(double x)
  17.         {
  18.             return Math.Log(x) * (Math.Sin(x) * Math.Sin(x) + Math.Sin(10 * x) * Math.Sin(10 * x));
  19.         }
  20.         static void Main(string[] args)
  21.         {
  22.             for (int i = 0; i < size; i++)
  23.             {
  24.                 wątki[i] = new Thread(new ThreadStart(max));
  25.                 wątki[i].Name = i.ToString();
  26.                 wątki[i].Start();
  27.             }
  28.             for (int i = 0; i < size; i++)
  29.             {
  30.                 Console.WriteLine(wyniki[i]);
  31.             }
  32.  
  33.             Console.ReadLine();
  34.         }
  35.        
  36.         static public void max()
  37.         {
  38.             double y = licznik + 1;
  39.             maximum = funkcja(y);
  40.             nastepna = funkcja(y + rozdzielczosc);
  41.             poprzednia = funkcja(y - rozdzielczosc);
  42.             do
  43.             {
  44.                 nastepna = funkcja(y + rozdzielczosc);
  45.  
  46.                 if (maximum <= nastepna)
  47.                 {
  48.                     poprzednia = maximum;
  49.                     maximum = nastepna;
  50.                 }
  51.                 else if (maximum <= poprzednia)
  52.                 {
  53.                     nastepna = maximum;
  54.                     maximum = poprzednia;
  55.                     rozdzielczosc*= (-1);
  56.                 }
  57.  
  58.             } while (maximum > nastepna && nastepna > poprzednia);
  59.             wyniki.Add(maximum);
  60.             licznik++;
  61.         }
  62.  
  63.        
  64.  
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement