Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: Solve::ivar: 0 is not a valid variable.
Posted:
Dec 14, 2012 2:58 AM
|
|
Use exact values until the last moment to enable simplifications when possible.
gamma = 3/2; m = 0; C0 = 1; CA = 2; CF = Sqrt[C0^2 + CA^2]; CT = (C0 CA)/CF; Ce = 1/2; CAe = 5; CFe = Sqrt[Ce^2 + CAe^2]; CTe = (Ce CAe)/CFe; delta = (2 C0^2 + gamma CA^2)/(2 Ce^2 + gamma CAe^2); kza = 1;
When using numeric techniques your function definitions should be restricted to numeric arguments.
k0[x_?NumericQ] := Sqrt[-(((x^2 - C0^2) (x^2 - CA^2))/((C0^2 + CA^2) (x^2 - CT^2)))]
ke[x_?NumericQ] := Sqrt[-(((x^2 - Ce^2) (x^2 - CAe^2))/((Ce^2 + CAe^2) (x^2 - CTe^2)))]
You used the wrong syntax for NSolve
NSolve[(delta*(x^2 - CAe^2)* k0[x]*BesselI[m + 1, k0[x]*kza])/BesselI[m, k0[x]*kza] + ((x^2 - CA^2)*ke[x]* BesselK[m + 1, ke[x]* kza])/BesselK[m, ke[x]*kza] == 0, x, Reals]
NSolve::nsmet:This system cannot be solved with the methods available to NSolve. >>
NSolve[ (4*(-25 + x^2)*BesselI[1, k0[x]]*k0[x])/ (19*BesselI[0, k0[x]]) + ((-4 + x^2)*BesselK[1, ke[x]]*ke[x])/BesselK[0, ke[x]] == 0, x, Reals]
When NSolve cannot be used, use FindRoot but you will need estimates of the roots. Plotting the function can help with this:
Plot[(delta (x^2 - CAe^2) k0[x] BesselI[m + 1, k0[x] kza])/ BesselI[m, k0[x] kza] + ((x^2 - CA^2) ke[x] BesselK[m + 1, ke[x] kza])/ BesselK[m, ke[x] kza], {x, -5.1, 5.1}, PlotRange -> {-20, 20}]
Plot[(delta (x^2 - CAe^2) k0[x] BesselI[m + 1, k0[x] kza])/ BesselI[m, k0[x] kza] + ((x^2 - CA^2) ke[x] BesselK[m + 1, ke[x] kza])/ BesselK[m, ke[x] kza], {x, 0.89, 0.94}]
FindRoot[(delta (x^2 - CAe^2) k0[x] BesselI[m + 1, k0[x] kza])/ BesselI[m, k0[x] kza] + ((x^2 - CA^2) ke[x] BesselK[m + 1, ke[x] kza])/ BesselK[m, ke[x] kza] == 0, {x, #}] & /@ Flatten[{-1.9, -0.93, -0.904, Range[-.897, -.894, .001], Range[.894, .897, .001], .904, .93, 1.9}] // Chop
{{x -> -2.}, {x -> -0.928239}, {x -> -0.898603}, {x -> -0.898603}, {x \ -> -0.895811}, {x -> -0.895102}, {x -> 0.928239}, {x -> -0.928239}, {x -> 0.895102}, {x -> 0.895811}, {x -> 0.898603}, {x -> 0.898603}, {x -> 0.928239}, {x -> 2.}}
The Chop is necessary to remove small imaginary artifacts arising from the numerical techniques.
These are not all of the roots since the function is highly oscillatory in some ranges.
Bob Hanlon
On Thu, Dec 13, 2012 at 4:08 AM, Ding Yuan <gardener_2003@hotmail.com> wrote: > Hello, > > I am fresh in Mathematica. Can anyone explain what is happening in this code? > > Cheers > > Ding > > > ------------ > gamma = 1.5; m = 0; > C0 = 1.; CA = 2; > CF = (C0^2 + CA^2)^0.5; CT = (C0 CA)/CF; > Ce = 0.5; CAe = 5 ; > CFe = (Ce^2 + CAe^2)^0.5; CTe = (Ce CAe)/CFe; > delta = (2 C0^2 + gamma CA^2)/(2 Ce^2 + gamma CAe^2); > kza = 1.; > k0[x_] := (-(((x^2 - C0^2) (x^2 - CA^2) )/((C0^2 + CA^2) (x^2 - > CT^2))))^0.5 > ke[x_] := (-(((x^2 - Ce^2) (x^2 - CAe^2))/((Ce^2 + CAe^2) (x^2 - > CTe^2))))^0.5 > NSolve[(delta (x^2 - CAe^2) k0[x] BesselI[m + 1, k0[x] kza])/ > BesselI[m, > k0[x] kza] + ((x^2 - CA^2) ke[x] BesselK[m + 1, ke[x] kza])/ > BesselK[m, ke[x] kza] == 0, {x, 0, 10}, Reals] > > NSolve::ivar: 0 is not a valid variable. >> > NSolve[(0.0941502 (-25 + > x^2) (-(((-4 + x^2) (-1. + x^2))/(-0.8 + x^2)))^0.5 BesselI[1, > 0.447214 (-(((-4 + x^2) (-1. + x^2))/(-0.8 + x^2)))^0.5])/ > BesselI[0, > 0.447214 (-(((-4 + x^2) (-1. + x^2))/(-0.8 + x^2)))^0.5] + ( > 0.199007 (-4 + > x^2) (-(((-25 + x^2) (-0.25 + x^2))/(-0.247525 + > x^2)))^0.5 BesselK[1, > 0.199007 (-(((-25 + x^2) (-0.25 + x^2))/(-0.247525 + > x^2)))^0.5])/ > BesselK[0, > 0.199007 (-(((-25 + x^2) (-0.25 + x^2))/(-0.247525 + > x^2)))^0.5] == 0, {x, 0, 10}, Reals] >
|
|
|
|