help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vectorize a function that depends on previous function value


From: Kai Torben Ohlhus
Subject: Re: Vectorize a function that depends on previous function value
Date: Mon, 19 May 2014 15:12:28 +0200

On Mon, May 19, 2014 at 1:08 PM, gergo <address@hidden> wrote:
Dear list members!

I have have a discrete time dynamical system:

function [a,b] = dynamicalSystmem(data, params)
a(n) = a(n-1) + data(n) + b(n-1) + someNonLinearFunction(a(n-1))
b(n) = b(n-1) + someOtherNonlinearFctn(a(n-1))

To fit the model to my data, I'm minimizing a simple cost function, which
requires me to iterate the dynamical system function. Currently this is done
by a simple for-loop, which makes the optimization very slow, because this
is done in every optimization step.

However I couldn't find a way to vectorize this for loop. Has anybody of you
an idea how to solve this?

Thank you very much in advance!

Gerald



--
View this message in context: http://octave.1599824.n4.nabble.com/Vectorize-a-function-that-depends-on-previous-function-value-tp4664169.html
Sent from the Octave - General mailing list archive at Nabble.com.

_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave


Hello Gerald,

From your code snippet I conclude, that you don't have data dependencies from the left hand side (lhs) to the rhs, like a(n) = a(n) + a(n -1), right? In your loop, your previous a(n) will be dropped and a(1) is generated by a different rule, still right? And someNonLinearFunction() is vectorized, too? In this case you should be able to do something like this:

n = 10;
a = rand (1,n);
b = rand (1,n);
data = "" (1,n);
a(2:end) = a(1:end - 1) + data(2:end) + b(1:end - 1) + sin(a(1:end - 1));
a(1) = rand;

HTH,
Kai

reply via email to

[Prev in Thread] Current Thread [Next in Thread]