Question: Trouble trying to follow on a least squares video

Hello everybody! 

Since least squares is not fully understood by me all that well, and the way my Dutch book throws me into the deep whitout really showing how things are done, i decided to look for some videos on Least Squares in Maple on YouTube. Well, i did found one, but then this happened. "Error, (in sum) summation variable previously assigned, second argument evaluates to 1 = 1 .. 5" I just want to go further with the video, but now im stuck and i have no clue how to go on. 

https://youtu.be/8zh73UrJW6M?t=948 This is the video at the moment the part where i get stuck is shown. 

I really like these sort of videos while they really do help out. I think its great. 

This is my maple worksheet:


 

with(Statistics); with(CurveFitting); with(LinearAlgebra); with(Optimization); with(plots); interface(imaginaryunit = I)

I

(1)

"f(x):=b[0]+(∑)(b[k]*sin(k*x))"

proc (x) options operator, arrow, function_assign; b[0]+sum(b[k]*sin(k*x), k = 1 .. 5) end proc

(2)

X := [seq(3.*k*(1/10), k = 1 .. 10)]

[.3000000000, .6000000000, .9000000000, 1.200000000, 1.500000000, 1.800000000, 2.100000000, 2.400000000, 2.700000000, 3.000000000]

(3)

Y := map(proc (x) options operator, arrow; x^2 end proc, X)

[0.9000000000e-1, .3600000000, .8100000000, 1.440000000, 2.250000000, 3.240000000, 4.410000000, 5.760000000, 7.290000000, 9.000000000]

(4)

F := CurveFitting:-LeastSquares(X, Y, x, curve = f(x))

HFloat(9.017880939782968)-HFloat(7.700034497920161)*sin(x)-HFloat(3.0589327899122045)*sin(2.*x)-HFloat(1.6899646233017431)*sin(3.*x)-HFloat(1.40247653582845)*sin(4.*x)-HFloat(0.82531550630546)*sin(5.*x)

(5)

smartplot(HFloat(9.017880939782968)-HFloat(7.700034497920161)*sin(x)-HFloat(3.0589327899122045)*sin(2.*x)-HFloat(1.6899646233017431)*sin(3.*x)-HFloat(1.40247653582845)*sin(4.*x)-HFloat(0.82531550630546)*sin(5.*x))

 

display(data, plot(f(x), x = 0 .. 3))

Warning, expecting only range variable x in expression b[0]+b[1]*sin(x)+b[2]*sin(2*x)+b[3]*sin(3*x)+b[4]*sin(4*x)+b[5]*sin(5*x) to be plotted but found names [b[0], b[1], b[2], b[3], b[4], b[5]]

 

Error, (in plots:-display) expecting plot structure but received: data

 

data := LinearAlgebra:-Transpose(`<,>`(`<|>`(.3000000000, .6000000000, .9000000000, 1.200000000, 1.500000000, 1.800000000, 2.100000000, 2.400000000, 2.700000000, 3.000000000), `<|>`(0.9000000000e-1, .3600000000, .8100000000, 1.440000000, 2.250000000, 3.240000000, 4.410000000, 5.760000000, 7.290000000, 9.000000000)))

Matrix(%id = 18446746050376108382)

(6)

p1 := plot(data, style = point, color = "green")

 

display(p1, plot(F, x = 0 .. 3), plot(x^2, x = 0 .. 3, color = "black"))

 

with(CurveFitting)

``

CurveFitting[Interactive](X, Y)

9.01788093978297-7.70003449792016*sin(x)-3.0589327899122*sin(2.*x)-1.68996462330174*sin(3.*x)-1.40247653582845*sin(4.*x)-.82531550630546*sin(5.*x)

(7)

smartplot(9.01788093978297-7.70003449792016*sin(x)-3.0589327899122*sin(2.*x)-1.68996462330174*sin(3.*x)-1.40247653582845*sin(4.*x)-.82531550630546*sin(5.*x))

 

with*LinearAlgebra

LinearAlgebra:-LeastSquares({Equate(`~`[f](X), Y)[]}, {seq(b[k], k = 0 .. 5)})

{b[0] = HFloat(9.017880939782952), b[1] = HFloat(-7.700034497920145), b[2] = HFloat(-3.0589327899122054), b[3] = HFloat(-1.6899646233017416), b[4] = HFloat(-1.4024765358284492), b[5] = HFloat(-0.8253155063054547)}

(8)

A, v := LinearAlgebra:-GenerateMatrix(Equate(`~`[f](X), Y), [seq(b[k], k = 0 .. 5)]); LinearAlgebra:-LeastSquares(A, v)

Vector[column](%id = 18446746050376098150)

(9)

Optimization:-LSSolve([v, A])

[2.61443732196701051, Vector[column](%id = 18446746050376094654)]

(10)

Optimization:-LSSolve([seq(f(X[k])-Y[k], k = 1 .. 10)])

Error, (in sum) summation variable previously assigned, second argument evaluates to 1 = 1 .. 5

 

NULL


Thank you very much! 

Greetings,

 

The Function
 

Download Least-Squares_Fitting_in_Maple_video.mw

Please Wait...