# How can I solve a set of non-linear equations?

I was wondering whether someone can give me an idea on how I can solve a set of non-linear equations with an unknown exponent

This is what I have:

• Known values: N, R

• Unknown values: λ, α, J

• Equations

J = N1 + a*R1^λ
J = N2 + a*R2^λ
J = N3 + a*R3^λ


The α, J, λ should be approximately the same in every equation

The only thing I know according to the author of the paper is that "... by solving the three unknowns J, a, λ with a least-square solution scheme"

I know about least-squares, but not how to apply it when the exponent is unknown along with sum of N.

• welcome here, may be you shall look at other questions on how you shall post your question. – Rorschach Aug 11 '13 at 13:20
• Hi! To add to Blackbird's comment, aside from the formatting bar at the top of the edit box, there is an editing help page to help with formatting code. Also, questions normally include a "minimal working example" of what you've tried, which is code folks can copy and paste to reproduce your problem. It should be syntactically correct (but not necessarily a correct program). – Michael E2 Aug 11 '13 at 13:38
• Hi there and thanks for the reply it is quite obvious that I am new here and therefore I have no idea on how a question suppose to look like... So, a big thanks to Blackbird for the tip!!! I am afraid I don't have any code as for now I am trying to find a method or a theory that can support my problem. I am not looking for a direct answer but for an approach. The only thing I know according to the Author of the paper is that... "By solving the three unknowns J2, a, l with a least- square solution scheme" I know about least-square but no when the exponent is unknown along with sum. of "N" – Ioannis Aug 11 '13 at 14:54
• You have 3 eqns, 3 unknowns so least squares should not be needed. Subtract n_i, i=1..3 from the respective equations. Then take logs. You now havea system that is linear in log(j-n_i), log(a), and lambda. Solve it and exponentiate where needed to solve for j and a. – Daniel Lichtblau Aug 11 '13 at 15:09

You can't solve this as it stands. You have one equation with 2 unknowns.

If you add eq1 to eq2 and multiply eq3 by 2 and take the difference, you get one equation with only a and lambda in it.

Clear[j, \[Lambda], a, n1, n2, n3, r1, r2, r3];

eq1 = j == n1 + a*r1^\[Lambda];
eq2 = j == n2 + a*r2^\[Lambda];
eq3 = j == n3 + a*r3^\[Lambda];
eq4 = Inner[Plus, eq1, eq2, Equal]


eq5 = Map[2 # &, eq3]


eq6 = Inner[Subtract, eq4, eq5, Equal]


data = {n1 -> 1, n2 -> 2, n3 -> 3, r1 -> 4, r2 -> 5, r3 -> 6};
Expand[eq6 /. data]


• You can get another independent equation from adding eq1 to eq3 and multiplying eq2 by 2 and taking the difference, for example. – obsolesced Jul 31 '16 at 13:26

The equations are non-linear, and won't have any analytic solution in general. Since there are as many equations as unknowns, FindRoot may be used to obtain a numeric solution. However, since a "least-square" solution scheme is proposed, and each (n[i],r[i]) satisfy the same equation

n[i_]=J-a*r[i]^λ;


we can use FindFit, which finds a least-squares fit by default.

To use either FindRoot or FindFit, we need numeric data, e.g.

n0 = {1,2,3};
r0 = {4,5,6};
{J0, a0, λ0} = {J, a, λ} /. FindFit[Transpose[{r0, n0}], n[i], {J, a, λ}, r[i]]


We can check FindRoot returns the same solution by

r[i_]:=r0[[i]]
FindRoot[Table[n[i]==n0[[i]],{i,3}],{{J,J0},{a,a0},{λ,λ0}}]

• I don't necessarily consider "(FindFit) ... doesn't require an initial guess" an advantage; you can use EvaluationMonitor to show that FindFit[] always uses a vector of all 1's as the initial guess, which may or may not be appropriate to the system at hand. – J. M.'s discontentment Jul 31 '16 at 14:39
• I stand corrected then.. Is there any way to change this guess? – obsolesced Jul 31 '16 at 17:50
• Certainly; as noted in the docs, you can supply seeds to FindFit[] as well, by providing a list of pairs of the parameter and its corresponding seed. In fact, quite a number of questions in here have answers where part of the advice goes like "you need to give FindFit[] better starting values". – J. M.'s discontentment Jul 31 '16 at 17:53
• Good to know. Thanks for pointing this out. Have edited out the offending claim. – obsolesced Jul 31 '16 at 17:55