1
$\begingroup$

This question already has an answer here:

I use the code below to create a table 4x16

Module[{r},
  Table[{n, ksi, r = c /. FindRoot[ SpheroidalS1[1, n, c, ksi], {c, BesselJZero[n + 1/2, 1]}], r*ksi},
   {n, 4}, {ksi, {100, 250, 600, 950}}] // Flatten[#, 1] & // 
    Prepend[(Style[#, 14, Bold] & /@ {"n", "ksi", "c", "c*ksi"})] //
    Grid[#, Frame -> All] &]

I want to use the fit command so that values from columns $ksi$ and $c*ksi$ are used to generate a cubic curve that fits the data, with $n=constant$.

For example, for $n=1$ data would be:

$\left( \begin{array}{cc} 100 & 466.544 \\ 250 & 1123.13 \\ 650 & 2697.06 \\ 950 & 4267.86 \\ \end{array} \right)$

How can we do this?

$\endgroup$

marked as duplicate by Feyre, MarcoB, m_goldberg, gwr, Simon Woods Mar 2 '17 at 20:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
$\begingroup$

My seasonal response is "Bah Humbug!" You're going to need a whole lot more than 4 data points to appropriately interpolate between values and probably a different curve form. Here are your 4 data points (in red) and a slightly denser set of points (in blue) and the cubic found with 4 data points.

n = 1;
tab = Table[{ksi, r = c /. FindRoot[SpheroidalS1[1, n, c, ksi],
  {c, BesselJZero[n + 1/2, 1]}]}, {ksi, {100, 250, 600, 950}}]
    (* {{100,4.665444475020363`},{250,4.492504774092105`},{600,4.495100228222793`},
       {950,4.492479383771217`}} *)
tab2 = Table[{ksi, r = c /. FindRoot[SpheroidalS1[1, n, c, ksi],
  {c, BesselJZero[n + 1/2, 1]}]}, {ksi, 100, 950, 25}]
(* {{100,4.665444475020363`},{125,4.486303224204139`},{150,4.492553272545449`},
    {175,4.497021232612173`},{200,4.516082367012433`},{225,4.48902047908868`},
    {250,4.492504774092105`},{275,4.495356052346296`},{300,4.508204491692646`},
    {325,4.490077014738384`},{350,4.492491412641697`},{375,4.4945840215211375`},
    {400,4.496415154038593`},{425,4.490638932874265`},{450,4.492485914148653`},
    {475,4.49413852479222`},{500,4.495625913555363`},{525,4.485003683919843`},
    {550,4.492483130830832`},{575,4.49384856335518`},{600,4.495100228222793`},
    {625,4.486198665717941`},{650,4.4924815300144845`},{675,4.493644790781071`},
    {700,4.494724971228242`},{725,4.482730958442134`},{750,4.492480525651615`},
    {775,4.4934937511090505`},{800,4.494443655600911`},{825,4.426792103519759`},
    {850,4.492479854421963`},{875,4.493377320007397`},{900,4.4942249298669905`},
    {925,4.5086119997826986`},{950,4.492479383771217`}} *) 

lm = LinearModelFit[tab, {x, x^2, x^3}, x]
Show[Plot[lm[x], {x, 100, 950}, PlotRange -> All], 
 ListPlot[tab, PlotStyle -> {PointSize[0.02], Red}],
 ListPlot[tab2]]

Data and bad fit

Update

Maybe it's worse than I thought. Here are the results using {ksi, 100, 950, 1}: Even more extreme points

$\endgroup$
0
$\begingroup$

Let's strip away some of the complexity and focus on what seems to be your main problem, of finding a fit for the data. Here is a the n=1 case:

n = 1; 
tab = Table[{ksi, r = c /. FindRoot[SpheroidalS1[1, n, c, ksi], 
      {c, BesselJZero[n + 1/2, 1]}]}, {ksi, {100, 250, 600, 950}}]

Now you can find a fit with a cubic as:

FindFit[tab, c1 + c2 x + c3 x^2 + c4 x^3, {c1, c2, c3, c4}, x]

{c1 -> 4.88008, c2 -> -0.00261266, c3 -> 4.93821*10^-6, c4 -> -2.75528*10^-9}

You can do the same thing for other n.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.