From help-request at octave dot org Mon Feb 7 21:54:38 2005 Subject: Re: 2 linear eq From: Geordie McBain To: shih lin Cc: help at octave dot org Date: Tue, 8 Feb 2005 13:44:29 -0500 On Mon, Feb 07, 2005 at 07:27:49PM -0800, shih lin wrote: > to solve 8x + y =-29 > 8x - y = -19 > > I do > > >> function z=f(x) > z=[8*x(1)+x(2)=-29, 8*x(1)-x(2)=-19]; > endfunction > >> fsolve("f",[0,0]) > error: invalid lvalue function called in expression > error: evaluating assignment expression near line 2, column 17 > error: evaluating assignment expression near line 2, column 4 > error: called from `f' > error: fsolve: evaluation of user-supplied function failed > >> > I am in GNU Octave, version 2.1.42 (i686-pc-cygwin), if anyone can point how to > upgrade I am highly appreciate(I get it just follow download website's > instruction) > > eric No, the function passed to fsolve shouldn't contain the equations, it should return the residuals. Here you'd need function z = f(x) z = [8,1;8,-1]*x + [29;19]; endfunction This works O.K.: octave> fsolve ("f", [0;0]) ans = -3.0000 -5.0000 However, since your equations are linear, you don't really need fsolve (it's only required for nonlinear equations). You can solve linear systems like yours by: octave> [8,1;8,-1] \ [-29;-19] ans = -3 -5 Geordie McBain www.aeromech.usyd.edu.au/~mcbain ------------------------------------------------------------- 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 -------------------------------------------------------------