Changeset 25510 in project


Ignore:
Timestamp:
11/16/11 15:08:39 (10 years ago)
Author:
Ivan Raikov
Message:

signal-diagram: integration with built-in Octave solver

Location:
release/4/signal-diagram/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/signal-diagram/trunk/examples/Izhikevich03_run.m

    r23951 r25510  
    66
    77autoload ("RS", Izhikevich03_defs );
     8autoload ("RS_event", Izhikevich03_defs );
    89autoload ("RS_initial", Izhikevich03_defs );
    910autoload ("IB", Izhikevich03_defs );
     
    1920
    2021t0 = 0.0;
    21 t1 = 150.0;
     22t1 = 500.0;
    2223
    23 RS_state = RS_initial;
    24 RS_ys = [[RS_state.t,RS_state.V]];
     24global RS_state
     25RS_state = RS_initial
     26RS_ys = [[RS_state.t,RS_state.U,RS_state.V,RS_state.spike]];
     27
     28tic;
    2529while (RS_state.t < t1)
    26   y = RS(RS_state);
    27   y.t
    28   RS_state.t = y.t;
    29   RS_state.U = y.U;
    30   RS_state.V = y.V;
    31   RS_state.spike = y.spike;
    32   RS_state.tspike = y.tspike;
    33   RS_ys = [RS_ys; [y.t,y.V]];
     30   y = RS(RS_state);
     31
     32   if (y.spike)
     33     RS_state.h = 1e-3;
     34     y = RS(RS_state);
     35   else
     36     if (RS_state.h < 0.25)
     37       RS_state.h = RS_state.h+1e-1;
     38     endif
     39   endif
     40
     41   RS_state.t = y.t;
     42   RS_state.U = y.U;
     43   RS_state.V = y.V;
     44   RS_state.spike = y.spike;
     45   RS_state.tspike = y.tspike;
     46   RS_ys = [RS_ys; [y.t,y.U,y.V,RS_state.spike]];
    3447endwhile
     48toc;
    3549
    3650# IB_state = IB_initial;
  • release/4/signal-diagram/trunk/signal-diagram.scm

    r25492 r25510  
    12301230        "function " (name/Octave (codegen-rv fcodegen)) " = " (name/Octave name) " (input)" nl
    12311231        (list "global " (intersperse globals " ") ";" nl)
    1232         (map (lambda (x) (list (name/Octave x) " = " (value->Octave (V:Sel x (V:Var 'input))) "; " nl)) input)   nl
     1232        (map (lambda (x) (list (name/Octave x) " = " (value->Octave (V:Sel x (V:Var 'input))) "; " nl)) input)
     1233        nl
    12331234        (map expr->Octave (append relations-expr (codegen-expr fcodegen))) nl
    1234         "end" nl))
     1235        "endfunction" nl))
    12351236
    12361237      (if (pair? events)
     
    12401241            "function " (name/Octave "retval") " = " (name/Octave (string-append (->string name) "_event")) " (input)" nl
    12411242            "retval = [" (intersperse event-vector ",") "];" nl
    1242             "end" nl))))
     1243            "endfunction" nl))))
    12431244         
    12441245     
    12451246      (if initial
    1246           (print-fragments
    1247            (list (name/Octave name) "_initial = "
    1248                  (value->Octave
    1249                   (V:Rec (map (lambda (x) (let ((n (car x)) (v (cadr x)))
    1250                                             (let ((v (cond ((and (or (number? v) (symbol? v))) v)
    1251                                                            ((boolean? v) (if v 'true 'false))
    1252                                                            (else v))))
    1253                                               (list n (V:C v)))))
    1254                               initial))) nl)))
     1247              (print-fragments
     1248               (list (name/Octave name) "_initial = "
     1249                     (value->Octave
     1250                      (V:Rec (map (lambda (x) (let ((n (car x)) (v (cadr x)))
     1251                                                (let ((v (cond ((and (or (number? v) (symbol? v))) v)
     1252                                                               ((boolean? v) (if v 'true 'false))
     1253                                                               (else v))))
     1254                                                  (list n (V:C v)))))
     1255                                  initial))) nl))
     1256              )
    12551257
    12561258
     
    12591261(define (codegen/scheme name f #!key (initial #f) (pre #t) (solver 'rk4b))
    12601262
    1261   (if (and solver (not (member solver '(rkfe rk3 rk4a rk4b rkhe rkbs rkf45))))
     1263  (if (and solver (not (member solver '(rkfe rk3 rk4a rk4b rkhe rkbs rkf45 ode15s))))
    12621264      (error 'codegen/scheme "unknown solver" solver))
    12631265
Note: See TracChangeset for help on using the changeset viewer.