作者: af2486 (我喜歡旅行)
標題: 您好,想請問關於mathematica的問題
時間: Wed Dec 8 17:39:28 2010
您好,之前在暑假的時候曾經請教過mathematica的問題,非常感激
不過現在又有些問題想請教,不知是否有空撥冗幫我看一下呢?謝謝!
這是您之前幫我改過的程式碼:
xiLimit = 15.;
Hankel1[m_, x_] :=
If[Abs[x] < xiLimit, BesselJ[m, x] + I BesselY[m, x],
Sqrt[2/(Pi*x)] Exp[I*(x - m/2*Pi - Pi/4)]];
BesselJp[m_, x_] :=
If[Abs[x] < xiLimit,
D[BesselJ[m, x1],
x1] /. {x1 -> x}, -Sqrt[2/(Pi*x)] Sin[(x - m/2*Pi - Pi/4)]];
BesselYp[m_, x_] :=
If[Abs[x] < xiLimit, D[BesselY[m, x1], x1] /. {x1 -> x},
Sqrt[2/(Pi*x)] Cos[(x - m/2*Pi - Pi/4)]];
Hankel1p[m_, x_] :=
If[Abs[x] < xiLimit, D[Hankel1[m, x1], x1] /. {x1 -> x},
I*Sqrt[2/(Pi*x)] Exp[I*(x - m/2*Pi - Pi/4)]];
kr[kz_, k_] := Sqrt[k^2 - kz^2];
\[Alpha]r[kz_, k_] := Sqrt[kz^2 - k^2];
f[kz_, opt_] := Module[{sub},
k0 = \[Omega] Sqrt[\[Epsilon]0 \[Mu]0] /. opt;
k1 = \[Omega] Sqrt[\[Epsilon]1 \[Mu]1] /. opt;
k2 = \[Omega] Sqrt[\[Epsilon]2 \[Mu]2] /. opt;
r0 = r0 /. opt;
r1 = r1 /. opt;
m = m /. opt;
kr0 = kr[kz, k0];
kr1 = kr[kz, k1];
\[Alpha]r2 = \[Alpha]r[kz, k2];
BJ00 = BesselJ[m, kr[kz, k0] r0];
BJ10 = BesselJ[m, kr[kz, k1] r0];
BJ11 = BesselJ[m, kr[kz, k1] r1];
BY10 = BesselY[m, kr[kz, k1] r0];
BY11 = BesselY[m, kr[kz, k1] r1];
BJp00 = BesselJp[m, kr[kz, k0] r0];
BJp10 = BesselJp[m, kr[kz, k1] r0];
BJp11 = BesselJp[m, kr[kz, k1] r1];
BYp10 = BesselYp[m, kr[kz, k1] r0];
BYp11 = BesselYp[m, kr[kz, k1] r1];
HA21 = Hankel1[m, I \[Alpha]r[kz, k2] r1];
HAp21 = Hankel1p[m, I \[Alpha]r[kz, k2] r1];
M = {{BJ00, 0, -BJ10, -BY10 , 0, 0, 0, 0},
{0, BJ00, 0, 0, -BJ10, -BY10, 0, 0},
{(\[Omega] \[Epsilon]0)/(kr0 r0) BJp00, (m kz)/(kr0^2 r0^2)
BJ00, -((\[Omega] \[Epsilon]1)/(kr1 r0))
BJp10, -((\[Omega] \[Epsilon]1)/(kr1 r0)) BYp10, -((m kz)/(
kr1^2 r0^2)) BJ10, -((m kz)/(kr1^2 r0^2)) BY10, 0, 0},
{(m kz)/(kr0^2 r0^2) BJ00, (\[Omega] \[Mu]0)/(kr0 r0)
BJp00, -((m kz)/(kr1^2 r0^2)) BJ10, -((m kz)/(kr1^2 r0^2))
BY10, -((\[Omega] \[Mu]1)/(kr1 r0))
BJp10, -((\[Omega] \[Mu]1)/(kr1 r0)) BYp10, 0, 0 },
{0, 0, BJ11, BY11 , 0, 0, -HA21, 0},
{0, 0, 0, 0, BJ11, BY11, 0, -HA21},
{0, 0, (\[Omega] \[Epsilon]1)/(kr1 r1)
BJp11, (\[Omega] \[Epsilon]1)/(kr1 r1) BYp11, (m kz)/(
kr1^2 r1^2) BJ11, (m kz)/(kr1^2 r1^2) BY11, (
I \[Omega] \[Epsilon]2)/(\[Alpha]r2 r1) HAp21, (
m kz)/(\[Alpha]r2^2 r1^2) HA21},
{0, 0, (m kz)/(kr1^2 r1^2) BJ11, (m kz)/(kr1^2 r1^2)
BY11, (\[Omega] \[Mu]1)/(kr1 r1) BJp11, (\[Omega] \[Mu]1)/(
kr1 r1) BYp11, (m kz)/(\[Alpha]r2^2 r1^2) HA21, (
I \[Omega] \[Mu]2)/(\[Alpha]r2 r1) HAp21}
} /. opt;
equ = Det[M];
Return[equ];
]
n0[lambda_] :=
Sqrt[1 + (0.68671749*lambda^2)/(lambda^2 -
0.072675189^2) + (0.43481505*lambda^2)/(lambda^2 -
0.11514351^2) + (0.89656582*lambda^2)/(lambda^2 - 10.002398^2)];
n1[lambda_] :=
Sqrt[1 + (0.6961663*lambda^2)/(lambda^2 - 0.0684043^2) + (0.4079426*
lambda^2)/(lambda^2 - 0.1162414^2) + (0.8974794*
lambda^2)/(lambda^2 - 9.896161^2)];
n2[lambda_] := 1.0;
opt[lambda_] := {m -> 1, \[Omega] -> 2 Pi/lambda, r0 -> 4.1,
r1 -> 62.5, \[Epsilon]0 -> n0[lambda]^2, \[Mu]0 ->
1., \[Epsilon]1 -> n1[lambda]^2, \[Mu]1 -> 1., \[Epsilon]2 ->
n2[lambda]^2, \[Mu]2 -> 1., kz -> y};
temp3 = NestList[{#[[1]] + 0.001, #[[3]], Re@y} /.
FindRoot[
f[y*(2 Pi/(#[[1]] + 0.001)), opt[#[[1]] + 0.001]] ==
0, {y, #[[3]]}] &, {0.999, 1.299, 1.45038}, 301][[2 ;; -1]]
Export["temp3.csv", temp3[[All, 3]]]
-------------------------------------------------------------
其中迴圈是用牛頓法在1~1.3之間每隔0.001找一次解
理想上想得到的解是約略成等差級數的解
可是現在遇到的問題是在某些點,找到的解會和上一點一樣,這並不是所想要的
請問這有可能程式哪邊出問題嗎?還是跟牛頓法有關呢?
不好意思麻煩了...謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.42.126