[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 2 linear eq
From: |
Geordie McBain |
Subject: |
Re: 2 linear eq |
Date: |
Tue, 8 Feb 2005 13:44:29 -0500 |
User-agent: |
Mutt/1.5.6+20040907i |
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
-------------------------------------------------------------
- 2 linear eq, shih lin, 2005/02/07
- Re: 2 linear eq, miguel manese, 2005/02/07
- Re: 2 linear eq, Mike Miller, 2005/02/07
- Re: 2 linear eq, miguel manese, 2005/02/08
- Re: 2 linear eq, Paul Thomas, 2005/02/08
- Re: 2 linear eq, Henry F. Mollet, 2005/02/08
- Re: 2 linear eq, Paul Laub, 2005/02/08
- Re: 2 linear eq, John W. Eaton, 2005/02/08
- Re: 2 linear eq, Przemek Klosowski, 2005/02/08
Re: 2 linear eq,
Geordie McBain <=