am1x

lab22a

Feb 29th, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Fortran 1.84 KB | Fixit | 0 0
  1. program Lab22
  2. use methods
  3.     implicit none
  4.     integer :: i, j, k, n, m, count
  5.     real(8) :: a, b, eps
  6.     real(8), allocatable :: grid(:,:), mapp(:,:), w(:), res(:)
  7.     n = 1000
  8.     m = 3
  9.     k = 1
  10.     count = 1000
  11.     allocate(grid(n,4),mapp(count,3),w(n), res(m))
  12.     !grid 1 - сетка 2 - значения функции 3 - значения с выбросами 4 - МНК значения
  13.     !mapp 1 - аргумент 2 - значения функции
  14.     a = -0.6d0
  15.     b = 0.6d0
  16.     w = 1d0
  17.     call gengrid(grid,n,a,b)
  18.     call MNK(grid,w,n,m,res)
  19.     do i = 1,n
  20.         grid(i,4) = pf(res,grid(i,1),m)
  21.     end do
  22.     !write(*,"(4f14.8)") (grid(i,:), i = 1,n)
  23.     !Построение полинома и вычисление фактической ошибки
  24.     do i = 1,count
  25.         mapp(i,1) = a + (b-a)*real(i-1,8)/real(count,8)
  26.         mapp(i,2) = pf(res,mapp(i,1),m)
  27.         mapp(i,3) = dabs(mapp(i,2) - f(mapp(i,1)))
  28.     end do
  29.     open(1, file = "Result.csv")
  30.     !open(2, file= "Err.csv")
  31.     write(1,*) "x", ";", "y", ";", "py", ";", "error"
  32.     do i = 1, count
  33.         write(1, "(f16.12, a, f16.12, a, f16.12, a, f16.12)") mapp(i,1),";", f(mapp(i,1)),";",mapp(i,2), ";", mapp(i,3)
  34.     end do
  35.  
  36.     !write(2,*) "n", ";", "maxerr"
  37.     !do i = 3,k
  38.         !allocate(grid(i,4),mapp(count,3),w(i), res(m))
  39.         !call gengrid(grid,i,a,b)
  40.         !call MNK(grid,w,i,m,res)
  41.         !do j = 1,count
  42.             !mapp(j,1) = a + (b-a)*real(j-1,8)/real(count,8)
  43.             !mapp(j,2) = pf(res,mapp(j,1),m)
  44.             !mapp(j,3) = dlog10(dabs(mapp(j,2) - f(mapp(j,1))))
  45.         !end do
  46.          !write(2,"(f16.12, a, f16.12)") real(i,8), ";", maxval(mapp(:,3))
  47.         !deallocate(grid, mapp, w, res)
  48.     !end do
  49.     close(1)
  50.     deallocate(grid, mapp, w, res)
  51.     !close(2)
  52.     pause
  53. end program Lab22
Add Comment
Please, Sign In to add comment