Message Boards Message Boards


Help with programming (finding roots)

Posted 9 years ago
2 Replies
2 Total Likes

Hi I have defined a two variable f(a,b) function and now I have to solve an equation where I have to call that function four times. I have to solve for one of those variable (a). For the other variable (b) I have assigned numerical values. The code is as follows (also attached): The computer is hanging. Can anyone help me?

n0 := 1.50355
ne := 1.64131
e := 1/ne
d := 1/n0
c := Sqrt[(e *Cos[a])^2 + (d *Sin[a])^2]
f[a_, b_] := (1/((e *Cos[a])^2 + (d *Sin[a])^2)) (e^2 - d^2) Sin[
    a] Cos[a] Sin[
    b] + (1/Sqrt[(e *Cos[a])^2 + (d *
          Sin[a])^2]) (1 - (e^2 d^2 (Sin[b])^2)/
       Sqrt[(e *Cos[a])^2 + (d *Sin[a])^2])^0.5 - (1/
     d) (1 - (d* Sin [b])^0.5)
b1 := (-14.78*Pi)/180
b2 := (5.0096*Pi)/180
b3 := (-5*Pi)/180
b4 := (16.95*Pi)/180
Solve[((f[a, b1] - f[a, b2])/(f[a, b3] - f[a, b4])) == 1, a]
POSTED BY: cleveland cav
2 Replies
Posted 9 years ago

Hi Cleveland,

The attached notebook revises your code. I have corrected some syntax issues, and used rules rather than Set (=) to define constant parameter values.

You will see that FindRoot does indeed provide solutions for a for 2 of your b values. In the other 2 cases it returns convergence warnings and invalid solutions. At the very end, all 4 {a,b} pairs are checked, and it is seen that the first and third are correct solutions, but the second and fourth are not.

You will also see that the 2 valid solutions are both complex. If all coefficients are Real, FindRoot will only return real solutions. However, you will see in a part of the notebook that, for your parameter values, FindRoot is indeed being given an equation with complex coefficients. Unless you expect complex solutions, you might want to check that the equations and parameter values are correct. (My experience with LC pretilt is that it is not a complex number.)

Best regards, David

*** Edit: Sorry -- I attached the wrong file. It has been updated.

POSTED BY: David Keith

To put code in your post please use the formatting tools at the top of the input area.


NSolve[x[a_] == 1, a]

should be

NSolve[x[a] == 1, a]

Your function x[a] is a complicated (and Complex in the sense of involving the complex plane) trigonometric expression. So it is not clear that you will converge easily to a solution. You may have better luck with FindRoot.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract