Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.2K Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Looking for help to solve an error in a FindRoot

Posted 10 years ago

Hi, So this is my code:

Subscript[R, p] = 0.1
Subscript[R, s] = 55
Subscript[\[Omega], p] = 1
Subscript[\[Omega], s] = 1.1
Subscript[\[Omega], c] = Subscript[\[Omega], p]
m = k^2

\[Epsilon] = Sqrt[10^(0.1 Rp) - 1]
k = 1/Subscript[\[Omega], s]
kprime = Sqrt[1 - k^2]
K = EllipticK[m]
Kprime = EllipticK[kprime^2]
k = Sqrt[(10^(0.1 Rp) - 1)/(10^(0.1 Rs) - 1)]
k1prime = Sqrt[1 - k1^2]
K1 = EllipticK[k1^2]

K1prime = EllipticK[k1prime^2]
N1 = (K1prime K)/(K1 Kprime)

N2 = Ceiling[N1]
ratio1 = K/Kprime
ratio[N2_, k1_] := (N2 K1)/K1prime
k1nouveau = FindRoot[ratio2[N2, k1] == ratio1, {k1, 0.00027140}]

when I want to evaluate the last line of my code I have this error:

FindRoot::nlnum: "The function value {-1.41019+1.4729[9.,0.0002714]} is not a list of numbers with dimensions {1} at {k1} = {0.0002714}. \!\(\*ButtonBox[\">>\",
Appearance->{Automatic, None},
BaseStyle->\"Link\",
ButtonData:>\"paclet:ref/FindRoot\",
ButtonNote->\"FindRoot::nlnum\"]\)"

I don't know what to do to solve this problem. Can someone help me please?

POSTED BY: Sahar Benalem
6 Replies
Posted 10 years ago

This

clear;

Is not a defined Mathematica function. That is indicated because it is shown in pale blue in your screen capture.

Perhaps you meant

Clear["Global`*"];

and wish it to erase all prior assignments. You can look that up in the documentation.

But I do not know that adding "clear;" to your code caused any problems. Probably it did nothing.

Then you define

ratio2[N2_, k1_] := (N2 K1)/K1prime

and it is not obvious to me if the calculation of ratio2 makes any use of the second argument or simply ignores it.

You do have multiple uses of k1 and K1 mixed together prior to this. I attempted to use Trace[] to track down exactly how the numeric values from FindRoot are used within the search process in your code and could not come up with a sufficiently simple explanation that I thought it would help.

Each of us makes changes and shows the other what we get and the other does the same and this repeats. But I am not sure we are making progress with this, it works for me without errors and it doesn't work for you with errors, again and again.

Attachments:
POSTED BY: Bill Simpson
Posted 10 years ago

Finally it worked and I have a good answer. Thank you so much for your time.

POSTED BY: Sahar Benalem
Posted 10 years ago

Like that?

ratio2[N2_, K1_] := (N2 K1)/K1prime

Because it doesn't work either for me

POSTED BY: Sahar Benalem
Posted 10 years ago

In your definition

ratio2[N2_, k1_] := (N2 K1)/K1prime;

should that be k1 or K1 on the left side?

If I change that to K1 I get a solution.

POSTED BY: Bill Simpson
Posted 10 years ago

There seem to be a handful of tiny typos in the code. Guessing how to fix those gives

In[1]:= Subscript[R, p] = 0.1;
Subscript[R, s] = 55;
Subscript[\[Omega], p] = 1;
Subscript[\[Omega], s] = 1.1;
Subscript[\[Omega], c] = Subscript[\[Omega], p];
m = k^2;
\[Epsilon] = Sqrt[10^(0.1 Subscript[R, p]) - 1];
k = 1/Subscript[\[Omega], s];
kprime = Sqrt[1 - k^2];
K = EllipticK[m];
Kprime = EllipticK[kprime^2];
k = Sqrt[(10^(0.1 Subscript[R, p]) - 1)/(10^(0.1 Subscript[R, s]) - 1)];
k1prime = Sqrt[1 - k1^2];
K1 = EllipticK[k1^2];
K1prime = EllipticK[k1prime^2];
N1 = (K1prime K)/(K1 Kprime);
N2 = Ceiling[N1];
ratio1 = K/Kprime;
ratio2[N2_, k1_] := (N2 K1)/K1prime;
k1nouveau = FindRoot[ratio2[N2, k1] == ratio1, {k1, 0.00027140}, MaxIterations -> 200]

Out[20]= {k1 -> 0.000177117}

Please check all of this very carefully in a freshly started notebook

POSTED BY: Bill Simpson
Posted 10 years ago

Thank you for you help!. I just copy paste your code (the image represents the code you gave me in my Mathematica) but it doesn't work again, enter image description here

I still have the same error and another one came up with your code. The errors I have are: enter image description here

Thanks again for helping me.

POSTED BY: Sahar Benalem
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard