Задание 2 - пункт 1
This commit is contained in:
		
						commit
						811fea30b8
					
				
					 6 changed files with 152 additions and 0 deletions
				
			
		
							
								
								
									
										37
									
								
								task2/01_maclaurin/app/Main.hs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								task2/01_maclaurin/app/Main.hs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | |||
| module Main where | ||||
| 
 | ||||
| import Graphics.EasyPlot | ||||
| 
 | ||||
| -- Шаг сетки | ||||
| delta = 0.001 | ||||
| 
 | ||||
| -- Функция | ||||
| u = sin | ||||
| 
 | ||||
| -- Точка | ||||
| t = 0.5 | ||||
| 
 | ||||
| -- Абсолютная погрешность | ||||
| err = 10 ** (-3) | ||||
| 
 | ||||
| main :: IO () | ||||
| main = do | ||||
|     let res = map (\(x,y) -> (fromIntegral x,y)) $ calc u t | ||||
|     plot X11 $ Data2D [Style Lines] [] res  | ||||
|     print res | ||||
| 
 | ||||
| 
 | ||||
| calc u t = calc' 0 [] u t where | ||||
|         calc' n stat u t | err' < err = (n, err') : stat | ||||
|                          | otherwise = (n, err') : calc' (n + 1) stat u t | ||||
|             where err' = abs (u t - maclaurin u t n)  | ||||
| 
 | ||||
| factorial n | n < 2 = 1 | ||||
|             | otherwise = n * factorial (n - 1) | ||||
| 
 | ||||
| diff u 0 h x = u x | ||||
| diff u n h x = (u' (x + h) - u' (x - h)) / (2 * h) where | ||||
|     u' = diff u (n - 1) h | ||||
| 
 | ||||
| maclaurin u x 0 = u 0 | ||||
| maclaurin u x n = (x ** (fromIntegral n)) * (diff u n delta 0) / (fromIntegral $ factorial n) + maclaurin u x (n - 1)    | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue