0

I want to solve one transcendental equation numerically. I have used the function 'solve' for the solution but my results are varied as compared to graphical solution. My code is written below and I am sending the graphical solution results.

clear all;
n1=1.77;
n2=1.45;
d=1e-6;
lambda = 1e-6;
ko = 2*pi/lambda;
A=(ko*n1)^2;
B=(ko*n2)^2;
r=(ko*d)*sqrt(n1^2-n2^2);
syms h;
s=((h*d)-m*pi) == 2*atan(sqrt(r^2/(h^2*d^2)-1));
solve (s)
prop=sqrt(A-ans^2);
neff=(prop*lambda)/(2*3.14)

where m will be varries from 0 to 2.0 with interval of 0.5. Graphical results are: m=0 neff is 1.7299 but graphical solution is 1.75 m=0.5 neff is 1.678 but graphical solution is 1.71 m=1.0 neff is 1.608 but graphical solution is 1.65 m=1.5 neff is 1.523 but graphical solution is 1.55 m=2.0 neff is 1.451 but graphical solution is 1.452

Can anyone please help me out and tell me the fault ? Also is there any other function can be used instead of 'solve'.

Thanks.

Rizwan
  • 21
  • 2
  • You've tagged this numerical methods but you're using symbolic math (`syms` and `solve`). If you're trying to obtain a numerical solution you should probably use a numerical root finder: `fzero` for 1-D. If you do use `solve`, you should replace `pi` with `sym(pi)`. Also should the `3.14` on the last line actually be `pi`? – horchler Nov 18 '13 at 16:49
  • thanks for your reply but as I am not good in programming, can you please tell me how to do it with fzero as I am trying and getting errors :( – Rizwan Nov 18 '13 at 17:17

1 Answers1

0

In principle, you need to do something like

fun = @(hd) ((hd)-m*pi)-2*atan(sqrt(r^2/(hd^2)-1));
fsolve(fun, 1.)

where I solved for the combined value hd=h*d, to avoid truncation errors in the terms h*d-m*pi and sqrt(r^2/(hd^2)-1).

das_blob
  • 51
  • 3