main.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <math.h>
  6. #include "header.h"
  7. int main() {
  8. srand(time(NULL));
  9. double a = 1, b = 3;
  10. double initial_a = 1; // çàäà÷à Êîøè y(1) = 1;
  11. char path[100];
  12. double* ans;
  13. double ugly_initial;
  14. int ugly_n = 1000;
  15. for (int n = 10;n <= 0;n++) {
  16. sprintf(path, "C:/Users/egorl/source/repos/gitbranch/num_methods_sem2/lab12/res/%i.txt",n);
  17. FILE* file;
  18. file = fopen(path, "w+");
  19. double* x = create_grid_even(n, a, b);
  20. double* y = euler_method(initial_a, a, b, f, n);
  21. for (int i = 0;i < n;i++) {
  22. fprintf(file, "%.16lf %.16lf", x[i], y[i]);
  23. if (i != n - 1) {
  24. fprintf(file, "\n");
  25. }
  26. }
  27. fclose(file);
  28. free(x);
  29. free(y);
  30. }
  31. double** ans_;
  32. for (int power = 1;power <= 6;power++) {
  33. FILE* file,*file_h;
  34. sprintf(path, "C:/Users/egorl/source/repos/gitbranch/num_methods_sem2/lab12/res/runge_%i.txt", power);
  35. file = fopen(path, "w+");
  36. sprintf(path, "C:/Users/egorl/source/repos/gitbranch/num_methods_sem2/lab12/res/runge_h_%i.txt", power);
  37. file_h = fopen(path, "w+");
  38. int n,len_h;
  39. ans_ = runge(pow(10,-power), initial_a, a, b, f,&n,&len_h);
  40. for (int i = 0;i < n;i++) {
  41. fprintf(file, "%.16lf %.16lf %.20lf", ans_[0][i], ans_[1][i], ans_[3][i]);
  42. if (i != n - 1) {
  43. fprintf(file, "\n");
  44. }
  45. }
  46. for (int k = 0;k < len_h;k++) {
  47. fprintf(file_h, "%.20lf", ans_[2][k]);
  48. if (k != len_h - 1) {
  49. fprintf(file_h, "\n");
  50. }
  51. }
  52. free(ans_[0]);
  53. free(ans_[1]);
  54. free(ans_[2]);
  55. free(ans_);
  56. fclose(file);
  57. fclose(file_h);
  58. }
  59. for (int procent=1;procent <= 0;procent++) {
  60. for (int i = 0;i < 20; i++) {
  61. sprintf(path, "C:/Users/egorl/source/repos/gitbranch/num_methods_sem2/lab12/res_additional/ugly_%i_%i.txt", procent,i+1);
  62. FILE* file;
  63. file = fopen(path, "w+");
  64. ugly_initial = uglify_initial(initial_a, procent, procent - 1);
  65. file = fopen(path, "w+");
  66. double* x = create_grid_even(ugly_n, a, b);
  67. double* y = euler_method(ugly_initial, a, b, f, ugly_n);
  68. for (int i = 0;i < ugly_n;i++) {
  69. fprintf(file, "%.16lf %.16lf", x[i], y[i]);
  70. if (i != ugly_n - 1) {
  71. fprintf(file, "\n");
  72. }
  73. }
  74. fclose(file);
  75. free(x);
  76. free(y);
  77. }
  78. }
  79. return 0;
  80. }