From help-request at octave dot org Mon Feb 7 22:29:25 2005 Subject: Re: 2 linear eq From: "shih lin" To: help at octave dot org Date: Mon, 7 Feb 2005 21:31:37 -0800 This is a multi-part message in MIME format... --nLLHebWs5sOrkT684c58yDd5R Content-Type: text/plain Content-Transfer-Encoding: 8bit Content-Disposition: inline thanks your help, but in a matlab 7 bood (mastering matlab7, by Duane Hanselman, Bruce Littlefield, by Prentice Hall) page 165, there is a line: /************************************************************/ >> mat2str(pi*eye(2)) % convert to matlab input syntax form! /***************************************************************/ it look for me the constant coefficent can put before the variable by * as multiplicstion even it is linear in matlab, /*I tried last time's quadratic eq, put a 8 * before both x(1), x(2) , it can run. in 2.1.42 */ regard eric >Date: Tue, 8 Feb 2005 13:44:29 -0500 > Geordie McBain shih lin Cc: help@octave.org > Re: 2 linear eq >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 > > >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 ------------------------------------------------------------ http://Game.37.com/ <--- Free Games http://newJoke.com/ <--- J O K E S ! ! ! --nLLHebWs5sOrkT684c58yDd5R-- ------------------------------------------------------------- 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 -------------------------------------------------------------