|
From: | Kai Torben Ohlhus |
Subject: | Re: Vectorize a function that depends on previous function value |
Date: | Mon, 19 May 2014 19:28:45 +0200 |
I do not think you can vectorize a time dependence relation easily,On Mon, May 19, 2014 at 3:52 PM, gergo <address@hidden> wrote:
>
> a = ones(10,1);
> a(2:end) = a(1:end-1) *2;
>
> This yields a = [1 2 2 2 ...]';
> What I needed was: a = [1 2 4 8 ...]';
>
> Any idea?
>
> Thanks
>
> Gerald
>
just try to vectorize
a(n) = a(n-1)+f(a(n-1));
This is exactly what integrators like lsode and ode45 do. What you can
do if your code is slow is to pass
that loop to C/C++ code.
https://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html
You can also try these tricks
https://www.gnu.org/software/octave/doc/interpreter/Vectorization-and-Faster-Code-Execution.html
Specially "Function Application" and "Accumulation"
_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave
[Prev in Thread] | Current Thread | [Next in Thread] |