[Top][All Lists]

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

Re: matrix of variables? <- thanks

From: jdonner
Subject: Re: matrix of variables? <- thanks
Date: Fri, 30 May 2003 18:53:39 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030513

Jeff wrote:
 I'm trying to solve a non-linear equation with 25 vars,
and it works when I number them from x(1) .. x(25) but,
they naturally are a 2D array of variables, is there some way I can I use matrix notation for convenience?
When I try to say this:
function y = f (x)
g = 0.9;
# center parts
y(2,2) = -1 * x(2,2) + (1/4)*g*(x(1,2) + x(2,1) + x(2,3) + x(3,2));
y(2,3) = -1 * x(2,3) + (1/4)*g*(x(1,3) + x(2,2) + x(2,4) + x(3,3));
... more

I get:
error: invalid column index = 2
error: evaluating binary operator `*' near line 4, column 13
error: evaluating binary operator `+' near line 4, column 22
error: evaluating assignment expression near line 4, column 8
error: called from `f'
error: fsolve: evaluation of user-supplied function failed

Is there a way to do this?

Heber Farnsworth wrote:
Define x as a vector and then reshape it into a matrix within the function.

x = reshape(x,5,5);

Thanks for that. Also, zeros(5,5) works as far as declaring x and y as 2D. I have to reshape at the end (I think) but at least octave is not complaining. Thanks again,

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

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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