2
$\begingroup$

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}]
$\endgroup$
  • $\begingroup$ Writing Eqt = Evaluate[Eq1[d] - 0.08*Eq2[d] == 0] will fix the error. $\endgroup$ – MikeY Dec 14 '19 at 1:54
4
$\begingroup$

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}*)
$\endgroup$
  • 2
    $\begingroup$ Or Solve[Eqt, d, Reals] . $\endgroup$ – Akku14 Dec 12 '19 at 20:35
  • $\begingroup$ 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? $\endgroup$ – Nini Dec 13 '19 at 16:40
  • $\begingroup$ @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. $\endgroup$ – Mariusz Iwaniuk Dec 13 '19 at 18:24
  • $\begingroup$ @MariuszIwaniuk Thanks for your help $\endgroup$ – Nini Dec 13 '19 at 18:46
2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Hi @Bill the code you provided doesn't give me any results. Do you know why? $\endgroup$ – Nini Dec 15 '19 at 21:44
  • $\begingroup$ Hi @Bill, I copied this code and ran it. It gives a graph without any data points on it. $\endgroup$ – Nini Dec 16 '19 at 16:40
  • $\begingroup$ 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. $\endgroup$ – Nini Dec 20 '19 at 18:29
  • 1
    $\begingroup$ 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 $\endgroup$ – Bill Dec 21 '19 at 19:53
  • $\begingroup$ Hi @Bill, the code worked. Thanks! $\endgroup$ – Nini Dec 26 '19 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.