Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 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.  
  7. namespace ConsoleApplication25
  8. {
  9. class Dane
  10. {
  11. public double h { get; set; }
  12. public double x0 { get; set; }
  13. public double y0 { get; set; }
  14. public double x1 { get; set; }
  15.  
  16. public Dane()
  17. {
  18. Console.WriteLine("Podaj h: ");
  19. h = double.Parse(Console.ReadLine());
  20.  
  21. Console.WriteLine("Podaj x0: ");
  22. x0 = double.Parse(Console.ReadLine());
  23.  
  24. Console.WriteLine("Podaj y0: ");
  25. y0 = double.Parse(Console.ReadLine());
  26.  
  27. Console.WriteLine("Podaj x1: ");
  28. x1 = double.Parse(Console.ReadLine());
  29. }
  30. }
  31.  
  32. class Program
  33. {
  34. static double f(double x, double y)
  35. {
  36. return x + y;
  37. }
  38. static void Main(string[] args)
  39. {
  40. var dane = new Dane();
  41.  
  42. double N = Math.Floor(Math.Abs((dane.x1 - dane.x0) / dane.h));
  43. double yn = dane.y0;
  44. double xn;
  45.  
  46.  
  47. for (int i = 0; i <= N; i++)
  48. {
  49. xn = dane.x0 + i * dane.h;
  50.  
  51. double k1 = dane.h * f(xn, yn);
  52. double k2 = dane.h * f(xn + 0.5 * dane.h, yn + 0.5 * k1);
  53. double k3 = dane.h * f(xn + 0.5 * dane.h, yn + 0.5 * k2);
  54. double k4 = dane.h * f(xn + dane.h, yn + k3);
  55.  
  56. yn = yn + (1.0 / 6) * (k1 + 2 * k2 + 2 * k3 + k4);
  57. }
  58. Console.WriteLine("y(" + dane.x1 + ") = " + yn);
  59. Console.ReadLine();
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement