Solve a function and save the curve

56 Views Asked by At

I have a function BesselJ[1, X] = BesselJ[0, Y] and I need to solve Y for a range of X and then use Y in a different equation. Z(X) = Y + const*X

I was only able to use ContourPlot to plot the first function but I want to create [X,Y] pair and then use loop to compute Z(X). I tried both NDSolve and Solve but they don't seem to be working for these special function.

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

I have no idea why you need to use NDsolve for as there is no differential equations here. And no body uses loops in Mathematica :) Use FindRoot to find the root and then plot the function z[x]. I used x as the guess where to start root search from when solving for y in BesselJ[1, x] == BesselJ[0, y] since one has to pick a point. Fee free to change this if you think there should be a better guess to use.

f[x_?NumericQ]:= Module[{y},y /.FindRoot[BesselJ[1, x] == BesselJ[0, y],{y, x}]];
const = 1;
z[x_] := f[x] + const*x
ListLinePlot[Table[{x, z[x]}, {x, 0.1, 10, .5}], Frame -> True, Mesh -> All, 
 PlotStyle -> {Red, PointSize[.02]}, 
 FrameLabel -> {{"z[x]", None}, {x, "z[x] vs. x"}}, GridLines -> Automatic, 
 GridLinesStyle -> LightGray]

Mathematica graphics

Plot[{BesselJ[1, x], BesselJ[0, x]}, {x, 0, 10}, 
   PlotLegends -> {"BesselJ[1,x]", "BesselJ[0,x]"}]

Mathematica graphics