2
$\begingroup$

I have the following data representing the normal displacement caused by a normal load applied at the middle cross section of a cylinder:

enter image description here

I've made the data available here.

I am trying to fit using the function:

$$ w=\sum_{i=1}^{n} A_{i}\cdot sin(j\theta)+B_{i}\cdot cos(j\theta) $$

where $A_{i}$ and $B_{i}$ are the unknown amplitudes to be found. I am using LeastSquares for this task:

theta = data[[All, 1]];
w = data[[All, 2]];

num = Dimensions[theta][[1]];
n = 5;

m = Table[
   Flatten[Table[{Sin[i1*theta[[i2]]], 0}, {i1, 1, n}]] + 
    Flatten[Table[{0, Cos[i1*theta[[i2]]]}, {i1, 1, n}]], {i2, 1, 
    num}];
x = LeastSquares[m, w];

f[t_] := Total[Flatten[Table[{Sin[i*t], Cos[i*t]}, {i, 1, n}]].x]
Plot[f[t], {t, -Pi, Pi}, PlotRange -> {{-1, 1}, {0, 0.030}}]

But it is resulting in an empty graphic:

enter image description here

Does anyone know what I am doing wrong?

$\endgroup$
  • 1
    $\begingroup$ Your data is screwy - using exponentiation with e has no meaning to Mathematica. Format it correctly and if you still have problems, update the data link. $\endgroup$ – ciao Mar 8 '14 at 7:19
  • 1
    $\begingroup$ Wouldn't Fourier be better for this than fitting ... ? $\endgroup$ – Szabolcs Sep 12 '16 at 16:05
  • 1
    $\begingroup$ @Saullo Castro Boa pergunta! Estava tendo o mesmo problema. Nos fóruns brasileiros é difícil obter uma resposta e aqui em São José dos Campos quase ninguém mexe com estas coisas... $\endgroup$ – LCarvalho Jun 12 '17 at 15:49
  • 1
    $\begingroup$ @LCarvalho sim... a solução sempre são os forums em inglês $\endgroup$ – Saullo G. P. Castro Jun 12 '17 at 16:13
2
$\begingroup$

After patching your data and fixing/adjusting code (removed unneeded Total, upped samples):

theta = data[[All, 1]];
w = data[[All, 2]];

num = Dimensions[theta][[1]];
n = 150;

m = Table[
   Flatten[Table[{Sin[i1*theta[[i2]]], 0}, {i1, 1, n}]] + 
    Flatten[Table[{0, Cos[i1*theta[[i2]]]}, {i1, 1, n}]], {i2, 1, 
    num}];
x = LeastSquares[m, w];

f[t_] := Flatten[Table[{Sin[i*t], Cos[i*t]}, {i, 1, n}]].x
Plot[f[t], {t, -Pi, Pi}, PlotRange -> {{-1, 1}, {0, 0.030}}]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ And to make this fitting success, the index of fitted function should start from $i=0$ :) $\endgroup$ – xzczd Mar 8 '14 at 7:48
  • $\begingroup$ @xzczd thank you for this comment, indeed there are cases where the series must start with $i=0$ $\endgroup$ – Saullo G. P. Castro Apr 7 '14 at 7:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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