# Help me to set up equation for FindRoot to solve

When I run the code I get this error message:

FindRoot::nlnum: The function value {Eq1 - 0.08*Eq2} is not a list of numbers with dimensions {1} at {d} = {0.001}.

How can I correct the error and find the value for d? And also I don't know how many roots can Eqt has.

(*initial values to obtain the root*)
a = 7.06; b = 0; c = 0.107763;

(*defining the equations*)
Eq1 [d_?NumericQ] :=
Eq1[d]= Simplify[((a-b)*((628*d)^(1-c))*Cos[c*Pi/2])];
Eq2 [d_?NumericQ] :=
Eq2[d] = Simplify[(1+2*((628*d)^(1-c))*Sin[c*Pi/2]+((628*d)^(2*(1-c)))];

(*define the equation which the root must be calculated*)
Eqt = Evaluate[Eq1 - 0.08*Eq2 == 0];
(*here I like to find the root d*)
FindRoot[Eqt, {d, 0.001}]

• Writing Eqt = Evaluate[Eq1[d] - 0.08*Eq2[d] == 0] will fix the error. – MikeY Dec 14 '19 at 1:54

Try this:

a = 7.06; b = 0; c = 0.107763;(*initial values to obtain the root*)(*defining the equations*)

Eq1 = ((a - b)*((628*d)^(1 - c))*Cos[c*Pi/2]);
Eq2 = 1 + 2*((628*d)^(1 - c))*Sin[c*Pi/2] + ((628*d)^(2*(1 - c)));
(*define the equation which the root must be calculated*)

Eqt = Eq1 - 0.08*Eq2 == 0;
FindRoot[Eqt, {d, 1/10000}]

(* {d -> 0.0000107223 } *)

FindRoot[Eqt, {d, 1/2}]

(*{d -> 0.23648} *)


If d is Real we have only 2 roots:

NSolve[Eqt && -100 < d < 100, d, Reals]
{{d -> 0.0000107223}, {d -> 0.23648}}


EDITED:

It is better to use exact numbers for that use Rationalize[0.265616, 0] function.

a = 7013/500;(*14.026*)
b = 241/25000000;(*9.64*10^(-6)*)
c = 16601/62500;(*0.265616*)
Eq1 = ((a - b)*((628*d)^(1 - c))*Cos[c*Pi/2]);
Eq2 = 1 + 2*((628*d)^(1 - c))*Sin[c*Pi/2] + ((628*d)^(2*(1 - c)));
Eqt = Eq1 - 8/100*Eq2 == 0;
sol = FindRoot[Eqt, {d, 1/10}, WorkingPrecision -> 100]

(*{d -> 1.59474734438386133056761886005121544936415083334269688311103192\
8277447098063374108097226699429567875*10^-6 -
3.11673146273605497900349372926910978847189125527343938927043516405\
9118848431652462070982280427383199*10^-117 I}*)

sol // Chop
(*{d -> 1.59474734438386133056761886005121544936415083334269688311103192\
8277447098063374108097226699429567875*10^-6}*)

• Or Solve[Eqt, d, Reals] . – Akku14 Dec 12 '19 at 20:35
• Thanks, @Mariusz Iwaniuk the script worked out. I have tried the script for other initial values a = 14.026; b = 9.64*10^(-6); c = 0.265616; and I get imaginary numbers for the roots. Can you help me to figure out why the roots are imaginary numbers? – Nini Dec 13 '19 at 16:40
• @Nini. In general any Mathematica function, works on complex numbers by default.Since the values have some precision, there will be small complex noise, which you can get rid of with Chop[] if you are so inclined.Try executed this code: Precision[7.06] and ?MachinePrecision and read in Documentation for more information. – Mariusz Iwaniuk Dec 13 '19 at 18:24
• @MariuszIwaniuk Thanks for your help – Nini Dec 13 '19 at 18:46

I guessed where to insert a missing ) in Eq2. If that was right then

Plot[ReIm[Eq1[d]-0.08*Eq2[d]],{d,-1/2,1/2}]


shows you approximately where the two roots are so you can give FindRoot good starting estimates.

• Hi @Bill the code you provided doesn't give me any results. Do you know why? – Nini Dec 15 '19 at 21:44
• Hi @Bill, I copied this code and ran it. It gives a graph without any data points on it. – Nini Dec 16 '19 at 16:40
• Hi @Bill, it is fine. I am using version 8. I haven't tried other functions. I don't know any of them to give me similar results. If you can give me suggestions it will be fantastic. – Nini Dec 20 '19 at 18:29
• Ah! That was the clue. If you look at the bottom of reference.wolfram.com/language/ref/ReIm.html?q=ReIm you should see that ReIm was introduced in version 10.1 which is why version 8 doesn't understand it. Hopefully this a=7013/500;b=241/25000000;c=16601/62500; Eq1[t_]:=((a-b)*((628*d)^(1-c))*Cos[c*Pi/2]); Eq2[t_]:=1+2*((628*d)^(1-c))*Sin[c*Pi/2]+((628*d)^(2*(1-c))); Plot[{Re[Eq1[d]-0.08*Eq2[d]],Im[Eq1[d]-0.08*Eq2[d]]},{d,-1/2,1/2}] should work for you in version 8 – Bill Dec 21 '19 at 19:53
• Hi @Bill, the code worked. Thanks! – Nini Dec 26 '19 at 14:39