help-octave
[Top][All Lists]

## syntax help: simple formula expansion (sub-indexes with vectors)

 From: edA-qa mort-ora-y Subject: syntax help: simple formula expansion (sub-indexes with vectors) Date: Thu, 03 Jun 2004 17:46:13 +0200 User-agent: Mozilla Thunderbird 0.6 (X11/20040502)

Although I've been working with octave for a little while now I am still having a lot of problems working with the most basic expressions. Can somebody please indicate to me the prefered way to handle the below example.
```
Given these variables (not in octave notation to avoid confusion):
l is a 2-space vector (ex. (4,5), in octave: [4,5])
x is a 2-space vector
h is a real number
n is an integer
i is the range of numbers [1,n]

I want to evalute the following function for every integer in i:

d(i) = l + ( h/n * ( i + 0.5 ) ) * x

```
I want to create the variable d that has the result of the function for each element of i. I try doing something like below, but I keep getting errors.
```
l=[1,1];
x=[0,1];
h=6;
n=3;
i=1:n
for q=i; d(q)=l-((h/n)*(q+0.5))*x; end

error: A(I) = X: X must be a scalar or a vector with same length as I

```
How do I do this? (If possible it'd be nice not to use a loop, but since I can't even get the loop working I feel unqualified to find a better solution)
```
--
edA-qa mort-ora-y
Idea Architect
http://disemia.com/

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```