Дифференцирование
This commit is contained in:
29
Носов Иван/README.md
Normal file
29
Носов Иван/README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Дифференцирование
|
||||
## Ссылка на видеоразбор
|
||||
https://youtu.be/Kh0shn9UW6Y
|
||||
## Код из книги
|
||||
#let rec differentiate x tm = match tm with
|
||||
Var y -> if y = x then Const "1" else Const "0"
|
||||
| Const c -> Const "0"
|
||||
| Fn("-",[t]) -> Fn("-",[differentiate x t])
|
||||
| Fn("+",[t1;t2]) -> Fn("+",[differentiate x t1;
|
||||
differentiate x t2])
|
||||
| Fn("-",[t1;t2]) -> Fn("-",[differentiate x t1;
|
||||
differentiate x t2])
|
||||
| Fn("*",[t1;t2]) ->
|
||||
Fn("+",[Fn("*",[differentiate x t1; t2]);
|
||||
Fn("*",[t1; differentiate x t2])])
|
||||
| Fn("inv",[t]) -> chain x t
|
||||
(Fn("-",[Fn("inv",[Fn("^",[t;Const "2"])])]))
|
||||
| Fn("^",[t;n]) -> chain x t
|
||||
(Fn("*",[n; Fn("^",[t; Fn("-",[n; Const "1"])])]))
|
||||
| Fn("exp",[t]) -> chain x t tm
|
||||
| Fn("ln",[t]) -> chain x t (Fn("inv",[t]))
|
||||
| Fn("sin",[t]) -> chain x t (Fn("cos",[t]))
|
||||
| Fn("cos",[t]) -> chain x t
|
||||
(Fn("-",[Fn("sin",[t])]))
|
||||
| Fn("/",[t1;t2]) -> differentiate x
|
||||
(Fn("*",[t1; Fn("inv",[t2])]))
|
||||
| Fn("tan",[t]) -> differentiate x
|
||||
(Fn("/",[Fn("sin",[t]); Fn("cos",[t])]))
|
||||
and chain x t u = Fn("*",[differentiate x t; u]);;
|
||||
113
Носов Иван/proizvodnaya.rkt
Normal file
113
Носов Иван/proizvodnaya.rkt
Normal file
@@ -0,0 +1,113 @@
|
||||
#lang racket
|
||||
(define (deriv exp var)
|
||||
(cond ((number? exp) 0)
|
||||
((variable? exp)
|
||||
(if (same-variable? exp var) 1 0))
|
||||
|
||||
((sum? exp)
|
||||
(make-sum (deriv (addend exp) var)
|
||||
(deriv (augend exp) var)))
|
||||
|
||||
((dif? exp)
|
||||
(make-dif (deriv (addend exp) var)
|
||||
(deriv (augend exp) var)))
|
||||
|
||||
((product? exp)
|
||||
(make-sum
|
||||
(make-product (multiplier exp)
|
||||
(deriv (multipicand exp) var))
|
||||
(make-product (deriv (multiplier exp) var)
|
||||
(multipicand exp))))
|
||||
|
||||
((exponentiation? exp)
|
||||
(make-product
|
||||
(make-product (exponent exp)
|
||||
(make-exponentiation (base exp) (- (exponent exp) 1)))
|
||||
(deriv (base exp)
|
||||
var)))
|
||||
|
||||
((sinus? exp)
|
||||
(make-product
|
||||
(deriv (base exp)
|
||||
var)(make-cos (base exp))))
|
||||
|
||||
((cosinus? exp)
|
||||
(make-product
|
||||
(deriv (base exp)var)(make-sin (base exp))))
|
||||
|
||||
((ex? exp)
|
||||
(make-product
|
||||
(deriv (base exp)
|
||||
var)(make-exp (base exp))))
|
||||
|
||||
|
||||
(else
|
||||
error "unknow expression type -- DERIV" exp)))
|
||||
|
||||
(define (ex? x)
|
||||
(and (pair? x) (eq? 'exp (car x))))
|
||||
|
||||
(define (make-exp a0)(list 'exp a0))
|
||||
|
||||
(define (sinus? x)
|
||||
(and (pair? x) (eq? 'sin (car x) )))
|
||||
|
||||
(define (make-cos a0)(list 'cos a0))
|
||||
|
||||
(define (cosinus? x)
|
||||
(and (pair? x) (eq? 'cos (car x) )))
|
||||
|
||||
(define (make-sin a0)(list '-sin a0))
|
||||
|
||||
(define (=number? exp num)
|
||||
(and (number? exp) (= exp num)))
|
||||
|
||||
(define (multipicand p) (caddr p))
|
||||
|
||||
(define (variable? x) (symbol? x))
|
||||
|
||||
(define (same-variable? v0 v1)
|
||||
(and (variable? v0) (variable? v1) (eq? v0 v1)))
|
||||
|
||||
(define (make-sum a0 a1)
|
||||
(cond ((and (number? a0) (number? a1)) (+ a0 a1))
|
||||
(else (list '+ a0 a1))))
|
||||
|
||||
(define (sum? x)
|
||||
(and (pair? x) (eq? (car x) '+)))
|
||||
|
||||
(define (dif? x)
|
||||
(and (pair? x) (eq? (car x) '-)))
|
||||
|
||||
(define (make-dif a0 a1)
|
||||
(cond ((and (number? a0) (number? a1)) (- a0 a1))
|
||||
(else (list '- a0 a1))))
|
||||
|
||||
(define (addend s) (cadr s))
|
||||
|
||||
(define (augend s) (caddr s))
|
||||
|
||||
(define (make-product m0 m1)
|
||||
(cond ((or (=number? m0 0) (=number? m1 0)) 0)
|
||||
((=number? m0 1) m1)
|
||||
((=number? m1 1) m0)
|
||||
((and (number? m0) (number? m1)) (* m0 m1))
|
||||
(else (list '* m0 m1))))
|
||||
|
||||
(define (product? x)
|
||||
(and (pair? x) (eq? (car x) '*)))
|
||||
|
||||
(define (multiplier p) (cadr p))
|
||||
|
||||
(define (make-exponentiation x n)
|
||||
(cond ((= n 0) 1)
|
||||
((= n 1) x)
|
||||
(else (list '** x n))))
|
||||
|
||||
(define (exponentiation? x)
|
||||
(and (pair? x) (eq? (car x) '**)))
|
||||
|
||||
(define (base s) (cadr s))
|
||||
|
||||
(define (exponent s) (caddr s))
|
||||
|
||||
Reference in New Issue
Block a user