Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
1  
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. –  rasher Mar 8 at 7:19

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
thank you a lot! –  Saullo Castro Mar 8 at 7:47
1  
And to make this fitting success, the index of fitted function should start from $i=0$ :) –  xzczd Mar 8 at 7:48
    
@xzczd thank you for this comment, indeed there are cases where the series must start with $i=0$ –  Saullo Castro Apr 7 at 7:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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