Hi Liam (& others)<br><br>I am getting funny behavior with the ODE stepper: <br><br>(As refresher, I am solving a 2nd order system that should reproduce a sinusoid)<br><br>A trace of the dydt function (sin-ode below) shows that it is always called with arguments (time 0 0), even though the initial conditions are (time 0 1) (see the let form). <br>
<br>It looks as if the initial conditions (stored in vector y below) are not passed as arguments to the dydt function (sin-ode). Or am I missing something?<br><br>I tried both the rk2 and rk4 steppers and different step sizes.<br>
<br>Thanks,<br><br>Mirko<br><br><br>Here is the source:<br><br>;;;; Example of a simple time-stepper<br>(defun sin-ode (time y z)<br> "Define ODE for a sinusoid<br><br>y''=-y <br><br>or as a system:<br><br>y'=z<br>
z'=-y<br><br>with initial conditions:<br><br>y0=0<br>z0=1 "<br> (declare (ignore time))<br> (values z (- y)))<br><br>(defun sin-ode-jacobian (time y z)<br> (declare (ignore time y z))<br> (values 0d0 0d0<br>
0d0 1d0<br> -1d0 0d0))<br>#|<br>(let ((time 0d0)<br> (delta-t 0.01d0)<br> (stepper-type +step-rk2+))<br> (let ((stepper (make-ode-stepper stepper-type 2 #'sin-ode #'sin-ode-jacobian))<br>
(y (make-marray 'double-float :dimensions 2))<br> (dydt-in (make-marray 'double-float :dimensions 2))<br> (dydt-out (make-marray 'double-float :dimensions 2))<br> (yerr (make-marray 'double-float :dimensions 2)))<br>
(setf (maref y 0) 0d0 ;; y(0)=0<br> (maref y 1) 1d0);; y'(0)=1<br> (multiple-value-bind (yp zp) (sin-ode time (maref y 0) (maref y 1))<br> (setf (maref dydt-out 0) yp<br> (maref dydt-out 1) zp))<br>
(dotimes (i 2)<br> (incf time delta-t)<br> (setf (maref dydt-in 0) (maref dydt-out 0)<br> (maref dydt-in 1) (maref dydt-out 1))<br> (format t "Y-in: ~12,4f, ~a, ~a~%" time (maref y 0) (maref y 1))<br>
(format t "dydt-in:~12,4f, ~a, ~a~%" time (maref dydt-in 0) (maref dydt-in 1))<br> (apply-step stepper time y delta-t yerr dydt-in dydt-out)<br> (format t "Y-out: ~12,4f, ~a, ~a~%" time (maref y 0) (maref y 1))<br>
(format t "dydt-out:~12,4f, ~a, ~a~%~%" time (maref dydt-out 0) (maref dydt-out 1)))<br> y))<br><br>|#<br>