Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question about overdefined system of nonlinear equations, fitting multiple variables

54 views
Skip to first unread message

Donna

unread,
Dec 10, 2009, 1:31:33 AM12/10/09
to
Hello all,

I would deeply appreciate any help that could be offered with this
question. I am fairly new to SciLab, but have some experience with
other packages (MATLAB, Maple, Mathematica, etc.). I have a system of
10 equations (data measurements) and 4 unknowns to solve for. The 10
equations are different measurements of data taken at different
angles, and are of the form:

y= -b + x_1 + x_2 * nx + x_3 * ny - (sqrt((x_1 + x_2 * nx + x_3 * ny)
^2 - 4*((x_2 * nx + x_1 * ny) * (x_1 * nx + x_3 * ny) - (( x_4 + x_1)
^2 * nx * ny))))

b is my measured data
nx and ny are related to the direction cosines of the angles at which
the measurements were taken (so there is 1 nx and 1 ny per b value)
x_1, x_2, x_3, and x_4 are the unknowns I need to solve for

I know that fsolve will not work because it is an overdefined system.
I have tried lsqrsolve but I am getting lots of errors regarding
incorrect multiplication or addition. (Occasionally I am getting an
Error 98 as well.) Currently I have b, nx, and ny all as column
vectors - should they be something else? My function definition is:

function y=qlfun(x,m)
x_1=x(1) ;x_2=x(2);x_3=x(3);x_4=x(4)
y= -b + x_1 + x_2 * nx + x_3 * ny - (sqrt((x_1 + x_2 * nx + x_3 * ny)
^2 - 4*((x_2 * nx + x_1 * ny) * (x_1 * nx + x_3 * ny) - (( x_4 + x_1)
^2 * nx * ny))))
endfunction

and the function call is
>[x,v]=lsqrsolve([1E9;1E9;1E9;1E9],qlfun,10)
!--error 8
inconsistent addition
at line 3 of function qlfun called by :
[x,v]=lsqrsolve([1E9;1E9;1E9;1E9],qlfun,10)


Do my constants (or my equation) need to be in some other form? Or
should I be using a different function, i.e. leastsq, or optim? I was
hoping lsqrsolve would do the trick because I believe the Levenberg-
Marquardt will solve this system...

Any help would be greatly appreciated, I have been banging my head
against this for some time now... thank you!

Serge Steer

unread,
Dec 10, 2009, 9:44:17 AM12/10/09
to
There was problems in your qlfun function the proper form is as follow:

function y=qlfun(x,m)
x_1=x(1) ;x_2=x(2);x_3=x(3);x_4=x(4)

y= -b + x_1 + x_2 * nx + x_3 * ny - ..
(sqrt((x_1 + x_2 * nx + x_3 * ny)^2 -..
4*((x_2 * nx + x_1 * ny) .* (x_1 * nx + x_3 * ny) -..
(( x_4 + x_1)^2 * nx .* ny))))
endfunction


Note that I uses .* instead of * for element wize vector multiplication.

Serge Steer


Donna a �crit :

Donna

unread,
Dec 10, 2009, 10:34:14 AM12/10/09
to
On Dec 10, 9:44 am, Serge Steer <Serge.St...@inria.fr> wrote:
> There was problems in your qlfun function the proper form is as follow:
>
> function y=qlfun(x,m)
>   x_1=x(1) ;x_2=x(2);x_3=x(3);x_4=x(4)
>   y= -b + x_1 + x_2 * nx + x_3 * ny - ..
>      (sqrt((x_1 + x_2 * nx + x_3 * ny)^2 -..
>            4*((x_2 * nx + x_1 * ny)  .* (x_1 * nx + x_3 * ny) -..
>               (( x_4 + x_1)^2 * nx .* ny))))
> endfunction
>
> Note that I uses .* instead of * for element wize vector multiplication.
>
> Serge Steer
>
> Donna a écrit :

Hello Serge,

Thank you, I will try that suggestion. I think I did at one point, but
it gave me an "inconsistent multiplication" error. Should b, nx, and
ny be in row vectors or column vectors?

Thank you very much for your help!

Donna

unread,
Dec 10, 2009, 11:14:33 PM12/10/09
to

Hello,

I made the changes you suggested and now I get Error 98, Variable
returned by function is incorrect. Does this mean I'm getting an
imaginary number back?

Thanks for any and all help!

Serge Steer

unread,
Dec 11, 2009, 10:40:57 AM12/11/09
to
Donna a �crit :

> On Dec 10, 10:34 am, Donna <dtw...@gmail.com> wrote:
>> On Dec 10, 9:44 am, Serge Steer <Serge.St...@inria.fr> wrote:
>>
>>
>>
>>> There was problems in your qlfun function the proper form is as follow:
>>> function y=qlfun(x,m)
>>> x_1=x(1) ;x_2=x(2);x_3=x(3);x_4=x(4)
>>> y= -b + x_1 + x_2 * nx + x_3 * ny - ..
>>> (sqrt((x_1 + x_2 * nx + x_3 * ny)^2 -..
>>> 4*((x_2 * nx + x_1 * ny) .* (x_1 * nx + x_3 * ny) -..
>>> (( x_4 + x_1)^2 * nx .* ny))))
>>> endfunction
>>> Note that I uses .* instead of * for element wize vector multiplication.
>>> Serge Steer
>>> Donna a �crit :
exactly, I got the same problem with random input because the argument
of sqrt became negative.
Serge

Donna

unread,
Dec 15, 2009, 5:13:32 PM12/15/09
to
On Dec 11, 10:40 am, Serge Steer <Serge.St...@inria.fr> wrote:
> Donna a écrit :

>
> > On Dec 10, 10:34 am, Donna <dtw...@gmail.com> wrote:
> >> On Dec 10, 9:44 am, Serge Steer <Serge.St...@inria.fr> wrote:
>
> >>> There was problems in your qlfun function the proper form is as follow:
> >>> function y=qlfun(x,m)
> >>>   x_1=x(1) ;x_2=x(2);x_3=x(3);x_4=x(4)
> >>>   y= -b + x_1 + x_2 * nx + x_3 * ny - ..
> >>>      (sqrt((x_1 + x_2 * nx + x_3 * ny)^2 -..
> >>>            4*((x_2 * nx + x_1 * ny)  .* (x_1 * nx + x_3 * ny) -..
> >>>               (( x_4 + x_1)^2 * nx .* ny))))
> >>> endfunction
> >>> Note that I uses .* instead of * for element wize vector multiplication.
> >>> Serge Steer
> >>> Donna a écrit :

Hi Serge,

THANK YOU for all your help. I went back and found there was an error
in my equation and now it works.

Merci beaucoup!

- Donna

0 new messages