Solving Over-determined Non-linear equations.
3 views (last 30 days)
Show older comments
Hi,
I have a set of 8 equations and 6 unknowns to solve for. All the 8 eqns are second order (quadratic) with each eqn having 4 unknowns.
I am listing two of them for eg. 4x^2 + 5y^2 -6x + 7y - 8xy + 6xz - 3yz - 5z + 2w + 9 = 0 ; 4u^2 + 5w^2 -5u + 8w - 9uw + 14uv - 13wv - 4v + 3x + 17 = 0 .. and so on.. with a total of 8 eqns.
The actual coefficients are very small numbers like 8.5e-4 and so on.. i have used integers here in the example to make it more comprehensible. The unknowns are x , y, z, u , v , w . Now how do I solve this system of eqns? I tried using fsolve and lsqnonlin.. Both don't seem to get me even closer to the answers.
I would really appreciate some help in this.
Thanks in advance, Venkat
4 Comments
bym
on 17 Aug 2011
I meant the system is linear, not non-linear as in the title. Please post & format the equations
Answers (6)
John Tillinghast
on 17 Aug 2011
It would help to see the code. In general, if you are doing complicated operations with small coefficients, you might want to rescale some of the variables so the coefficients are a bit bigger.
Presumably you are trying to minimize some "discrepancy" function (penalty function) for the equations. For example, if you have equations like
a1*x + b1*y = c1 a2*x + b2*y = c2 ...
your penalty function might be something like
sum_i( (a_i * x + b_i * y - c_i)^2 ) [not matlab code, just my notation]
But it's possible that some of the terms are more important than others, so you might really need to minimize
(a1*x + b1*y-c1)^2 + 10 * (a2*x + b2*y-c2)^2 + 100 * (a3*x + b3*y-c3)^2
i.e. a weighted sum instead of the unweighted sum.
But please post the code.
3 Comments
Jobayer Rahman
on 17 Oct 2016
Edited: Walter Roberson
on 17 Oct 2016
%fx=3x^3-5x^2+5x-7
%fdx=9x^2-10x+3
x(1);
kk(1)=1;
for k=1:100;
fx=3x(k)^3-5x(k)^2+3(k)-7;
fdx=9x(k)^2-10x(k)+3;
h=-fx/fdx;
x(k+1)=x(k)+h;
kk(k+1)=k+1;
if abx(h)<.0000001
break,end
end
disp([kk1'x'])
is it correct program...can you please check with your matlab program. my matlab getting some problem so that i ask you to just check and run for me. inform me the result...
Walter Roberson
on 17 Oct 2016
fx=3x(k)^3-5x(k)^2+3(k)-7 is not valid MATLAB syntax. MATLAB requires that you use * or .* to indicate multiplication
bym
on 19 Aug 2011
I will refer to your equations as eq1 through eq8. You'll notice that the higher order terms have the same coefficients (this is a clue). For example, subtracting eq3 from eq4 you are left with an expression in just x,y,z.
So, I got a system of 6 equations and unknowns by doing the following :
eq2-eq1 ;eq3-eq2;eq4-eq3;eq8-eq7;eq7-eq6;eq6-eq5
that gave me a coefficient matrix
A =
6e-006 -0.000143 -3.62e-005 0 0 4.0001
-1.1e-005 -4.3e-005 -8.1e-005 0 -1.6027e-006 -4
1e-006 3.5e-005 -3.4e-005 0 0 0
0 0 0 -0.0001692 -3.4e-005 3.4e-005
0 0.000109 -1.6027e-006 0.0001572 -8.37e-005 -4.2e-005
0 0 0 4e-006 -2.83e-005 3.4e-005
and a constant vector
b =
1.09
-1.0899
5.1e-006
1.7e-006
7.05e-005
5e-006
which can be solved using mldivide
c =A\b
c =
-36.231
0.81734
-0.37424
0.033565
0.15554
0.27257
This problem is very sensitive to round off errors, if you have the symbolic tool box you can solve it more accurately
5 Comments
bym
on 29 Aug 2011
@Venkat - I have not had a chance to revisit this. It sounds as if you are doing some electrical engineering problem. If you can explain what you are trying to from that aspect, maybe others on the forum could help (I am a mechanical engineer by training)
Walter Roberson
on 29 Aug 2011
I followed proecsm's lead but with slightly different arrangements of the equations, using eq1-eq2, eq1-eq3, eq1-eq4, eq5-eq6, eq5-eq7, eq5-eq8
Then substituting the names x, y, z, u, v, w in for X(1,1), X(2,1) and so on, and converting the result to a set, I was able to use Maple:
LinearAlgebra[LeastSquares](
{.50e-5+.283e-4*v-.34e-4*u-.40e-5*w = 0,
1.0899998+.362e-4*x+.143e-3*y-.6e-5*z-4.000109*u = 0,
.644e-4+.1172e-3*x+.186e-3*y+.5e-5*z-.109e-3*u+.16027e-5*v = 0,
.695e-4+.1512e-3*x+.151e-3*y+.4e-5*z-.109e-3*u+.16027e-5*v = 0,
.755e-4+.112e-3*v+.8e-5*u-.109e-3*y-.1612e-3*w+.16027e-5*x = 0,
.772e-4+.146e-3*v-.26e-4*u-.109e-3*y+.8e-5*w+.16027e-5*x = 0},
{x,y,z,u,v,w})
This yielded the result,
{u = .27256965857615293077411639983502007553428451870328,
v = .15277278781877226253617051867622720938483268112186,
w = .14025375920513845863417021036636864356272827882778e-1,
x = -.24280430676962935958328829284572825211877450016313,
y = .84533097654555229286657861791163208120617978613903,
z = -32.741930609261728476162053583661883414254625520422}
On the other hand, this is the same as is exactly the same result as you get if you submit that list of 6 equations to simple solve() -- with there only being 6 equations in 6 unknowns, there is no invocation of least-squares solution.
If one substitutes the above results back in to the original 8 equations, the results are not great -- 4 nearly identical residues on the order of +0.01, and 4 nearly identical residues on the order of -0.00001 .
I would thus say that reducing the 8 equations to 6 is not going to work properly for a least-squared solution.
Unfortunately I do not have a recommendation at present; I thought I knew how to deal with x^2 and x*y and so on, but about a week ago, I managed to prove to myself that my technique was fundamentally flawed,, and I have not yet had Time To Go Back To The Old Drawing Board.
See Also
Categories
Find more on Assembly in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!