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!
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!
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!
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