Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Euler-method/Common-Lisp/euler-method-1.lisp
Normal file
26
Task/Euler-method/Common-Lisp/euler-method-1.lisp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
;; 't' usually means "true" in CL, but we need 't' here for time/temperature.
|
||||
(defconstant true 'cl:t)
|
||||
(shadow 't)
|
||||
|
||||
|
||||
;; Approximates y(t) in y'(t)=f(t,y) with y(a)=y0 and t=a..b and the step size h.
|
||||
(defun euler (f y0 a b h)
|
||||
|
||||
;; Set the initial values and increments of the iteration variables.
|
||||
(do ((t a (+ t h))
|
||||
(y y0 (+ y (* h (funcall f t y)))))
|
||||
|
||||
;; End the iteration when t reaches the end b of the time interval.
|
||||
((>= t b) 'DONE)
|
||||
|
||||
;; Print t and y(t) at every step of the do loop.
|
||||
(format true "~6,3F ~6,3F~%" t y)))
|
||||
|
||||
|
||||
;; Example: Newton's cooling law, f(t,T) = -0.07*(T-20)
|
||||
(defun newton-cooling (time T) (* -0.07 (- T 20)))
|
||||
|
||||
;; Generate the data for all three step sizes (2,5 and 10).
|
||||
(euler #'newton-cooling 100 0 100 2)
|
||||
(euler #'newton-cooling 100 0 100 5)
|
||||
(euler #'newton-cooling 100 0 100 10)
|
||||
13
Task/Euler-method/Common-Lisp/euler-method-2.lisp
Normal file
13
Task/Euler-method/Common-Lisp/euler-method-2.lisp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
;; slightly more idiomatic Common Lisp version
|
||||
|
||||
(defun newton-cooling (time temperature)
|
||||
"Newton's cooling law, f(t,T) = -0.07*(T-20)"
|
||||
(declare (ignore time))
|
||||
(* -0.07 (- temperature 20)))
|
||||
|
||||
(defun euler (f y0 a b h)
|
||||
"Euler's Method.
|
||||
Approximates y(time) in y'(time)=f(time,y) with y(a)=y0 and t=a..b and the step size h."
|
||||
(loop for time from a below b by h
|
||||
for y = y0 then (+ y (* h (funcall f time y)))
|
||||
do (format t "~6,3F ~6,3F~%" time y)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue