help-octave
[Top][All Lists]
Advanced

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

Re: 2 linear eq


From: shih lin
Subject: Re: 2 linear eq
Date: Mon, 7 Feb 2005 21:31:37 -0800

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 <address@hidden> shih lin <address@hidden>Cc: address@hidden
> 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  ! ! !

reply via email to

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