help-octave
[Top][All Lists]
Advanced

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

Re: Function matrix/vector assembly


From: marco atzeri
Subject: Re: Function matrix/vector assembly
Date: Thu, 09 Aug 2012 07:06:34 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0

On 8/9/2012 6:48 AM, Grant Stephens wrote:
Good Morning

I am trying to assemble a function into a matrix or a vector but I have
not found a way to do so except for typing it out manually, which is not
possible as the it would be around 100 long and wide and changes after
every timestep. The following represents what I am trying to do:

f=@(x) [x^2 x 1]
then I want to put a number of these into a vector so that the final
vector would look like:
vect=@(x) [x^2 x+x^2 1+x 1]
Here I have added have done something like:
vect=@(x) [f(x)(1) f(x)(2)+f(x)(1) f(x)(3)+f(x)(2) +f(x)(3)]
So basically having a vector with f in 1 to 3 added to f in positions 2
to 4. Obviously this would have to run in a loop as it is well over 100
wide.

Not clear to have understood you need, something like this ?

octave:1> a=1:10
a =

    1    2    3    4    5    6    7    8    9   10

octave:2> a(1:end-1)
ans =

   1   2   3   4   5   6   7   8   9

octave:3> a(2:end)
ans =

    2    3    4    5    6    7    8    9   10

octave:4> a(1:end-1)+a(2:end)
ans =

    3    5    7    9   11   13   15   17   19


Does anybody have any ideas? Am I missing something simple?

Thank you.

Marco




reply via email to

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