[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: nonlinear equation help
From: |
Ben Abbott |
Subject: |
Re: nonlinear equation help |
Date: |
Fri, 02 Sep 2011 17:28:48 -0400 |
On Sep 2, 2011, at 3:38 PM, fv2005 wrote:
> I already specified that we use information found online. I referred to the
> Octave documentation.
> Here it's my work script:
> global w5 = 5.83*72; h5 = 8.27*72; lm = 0.78; rm = 0.3;
> global wb = 504; hb = 662; lb = 71; tb = 43; rb = 433; bb = 604;
> rb = wb-rb;
> bb = hb-bb;
>
> function y = f(x)
> y = zeros(3,1);
> global w5;
> global wb;
> global lb;
> global rb;
> global lm;
> global rm;
> y(1) = w5 - x(1)*(wb+x(2)+x(3));
> y(2) = x(1)*(x(2)+lb) - 72*lm;
> y(3) = x(1)*(x(3)+rb) - 72*rm;
> endfunction
>
> [x, info] = fsolve (@f, [1; 3]);
>
> When i run this script i got this error:
> error: A(I): Index exceeds matrix dimension.
> error: called from:
> error: f at line 33, column 7
As was pointed out you've written a function of three inputs, but only provided
two inputs. If you add a third then it should work.
> [x, info] = fsolve (@f, [1; 3; 0]);
I noticed you also defined some variables that you didn't use (h5, tb). Was
that on purpose?
In any event, you can simplify the problem definition and avoid the use of
global variables by ...
> clear all
>
> w5 = 5.83*72;
> lm = 0.78;
> rm = 0.3;
> wb = 504;
> hb = 662;
> lb = 71;
> rb = wb-433;
> bb = hb-604;
>
> fcn = @(x) [w5-x(1)*(wb+x(2)+x(3)),
> x(1)*(x(2)+lb)-72*lm,
> x(1)*(x(3)+rb)-72*rm]
>
> x = fsolve (fcn, [0 0 0])
The result is ...
> warning: matrix singular to machine precision, rcond = 0
> x =
>
> 0.94475 -11.55579 -48.13684
>
>>> fcn (x)
> ans =
>
> -8.2097e-09
> -3.7446e-09
> 5.4826e-10
Ben