help-octave
[Top][All Lists]
Advanced

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

Re: solve simultaneous equation (novice)


From: Germán Arias
Subject: Re: solve simultaneous equation (novice)
Date: Sun, 25 May 2014 13:43:40 -0600
User-agent: GNUMail (Version 1.2.1)

Hi,

On 2014-05-25 13:05:36 -0600 message <address@hidden> wrote:

> Readers,
> 
> The function 'fsolve' was attempted to be used to solve the following 
> simultaneous equations:
> 
> equation 1: 4.2=2x+4y; equation 2: 6.3=4x+y
> 
> function y=f(x)
> ya=-4.2+2*x+4*4.2/4-2*x/4;
> yb=-6.3+4*x+4.2/4-2*x/4;
> endfunction
> [x,info]=fsolve(@f,[1;2])
> 
> warning: f: some elements in list of return values are undefined
> warning: f: some elements in list of return values are undefined
> warning: f: some elements in list of return values are undefined
> warning: f: some elements in list of return values are undefined
> warning: f: some elements in list of return values are undefined
> warning: f: some elements in list of return values are undefined
> x =
> 
>     1
>     2
> 
> info = [](0x0)
> 
> Manual solution:
> 
> Rearrangement to
> 4y=4.2-2x, 4.2/4-2x/4
> 
> 6.3=4x+4.2/4-2x/4 -> 25.2=16x+4.2-2x -> 25.2-4.2=16x-2x -> 21=14x -> x=3/2
> 
> 4.2=2*3/2+4y -> 4.2=3+4y -> 1.2=4y -> 1.2/4=y -> y=.3
> 
> Please what is my error in octave syntax to prevent the same result in octave 
> as in the manual method described?
> 

Solution:

>> function y = f(x)
y = zeros (2, 1);
y(1) = -4.2 + 2*x(1) + 4*x(2);
y(2) = -6.3 + 4*x(1) + x(2);
endfunction
>> [x, fval, info] = fsolve (@f, [1; 2])
x =

   1.50000
   0.30000

fval =

   9.1673e-12
   2.2204e-16

info =  1

See page 470 of the manual.

Germán.




reply via email to

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