Question: Using the Least Squares Approximation

Hello, I would like to use the LeastSquares subpackage in the LinearAlgebra package in order to solve the following problem:

 

Set of data: (1.0,2.33),(2.0,0.0626),(3.0,-2.16),(4.0,-2.45),(5.0,-0.357),(6.0,2.21),(7.0,2.75),(8.0,0.636),(9.0,-2.45).

I am trying to put the above data in the curve y=a+b*cos(x)+c*sin(x)+d*cos(2x)+e*sin(2x).

 

My attempt to solve this:

 

restart;

with(LinearAlgebra);

with(linalg);

with(CurveFitting);

LeastSquares([1.0, 2.33], [2.0, 0.626e-1], [3.0, -2.16], [4.0, -2.45], [5.0, -.357], [6.0, 2.21], [7.0, 2.75], [8.0, .636], [9.0, -2.45], x, curve = a+b*cos(v)+c*sin(v)+d*cos(2*x)+e*sin(2*x));

However, this returns an error: "Error, (in CurveFitting:-LeastSquares) 3rd argument must have type name". Any suggestions how to do this in order to find the coefficients a,b,c,d,e that most closely model the data given.? Also, can someone tell me what is wrong with my code above?

 

 

Please Wait...