Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
least squares minimization

Subject: least squares minimization

From: Alex

Date: 6 Jul, 2011 16:46:09

Message: 1 of 2

I have the following equation that i want to find the parameters c1, c2 and c3.

E = SUM(yj-(1/(c1*c2))*(c3-asinh(sinh(c3)*exp(c1*j*2*pi))))^2

yj is consecutive timings for a tennis ball, on a string revolving around a pole (the ball cannot change height)

I have found some help with this:

x = [ 1,2,3,4,5 ];

y = [ 2.2, 1.9, 1.7, 1.5, 1.4];

a11 = sum(x.^2); a12 = sum(x); a21 = sum(x); a22 = sum(ones(1,length(x)));

A = [ a11,a12; a21,a22] % the coefficient matrix of the minimization problem
c1 = 1;
c2 = 1;
c3 = 1;
diff_c1 = (c3-asinh(exp(2*pi*x.*c1).*sinh(c3)))/(c1^2*c2)+(2*x.*pi*exp(2*c1*x.*pi).*sinh(c3)*asinh(exp(2*c1*x.*pi).*sinh(c3)))/(c1*c2)
diff_c2 = (c3-asinh(exp(2*c1*x.*pi).*sinh(c3)))/(c1*c2^2)
diff_c3 = (exp(2*c1*x.*pi).*cosh(c2)*asinh(exp(2*c1*x.*pi).*sinh(c3))-1)/(c1*c2)
b1 = sum(diff_c1*y); b2 = sum(diff_c2*y); b3 = sum(diff_c3*y);

b = [ b1; b2; b3 ] % right-hand-side of the minimization problem

c = A \ b % solution of the minimization problem

xApr = 0 : 0.001 : 1; yApr = c(1)*xApr + c(2);

plot(x,y,'*g',xApr,yApr,'b');

Basically diff_c1,c2,c3 are the parts multiplied by the data values yj for least squares minimization, i think this is correct. b1,2,3 are these multiples.

I think the problem is I haven't got my '.''s in the correct place. I know that they are required to say do this for all x and y's but Im not sure exactly where they are required.

I have posted this here because I would also appreciate some help as to whether I am doing this the correct way - because I also require initial values of c1,2,3 which i have stated as 1 but again I am not sure if I have done that correctly

Subject: least squares minimization

From: Alan Weiss

Date: 7 Jul, 2011 11:45:06

Message: 2 of 2

If you have Optimization Toolbox, take a look at lsqcurvefit:
http://www.mathworks.com/help/toolbox/optim/ug/brn4noo.html#brp3l6v-1

If you have Statistics Toolbox, take a look at nlinfit:
http://www.mathworks.com/help/toolbox/stats/bq_676m-43.html#bq_676m-44

By saying
c = A \ b % solution of the minimization problem
you are assuming that the regression is linear. But it obviously is not.
You need a nonlinear model.

In your MATLAB code you also need to use ./ instead of / for division of
vectors.

Good luck,

Alan Weiss
MATLAB mathematical toolbox documentation

On 7/6/2011 12:46 PM, Alex wrote:
> I have the following equation that i want to find the parameters c1, c2
> and c3.
>
> E = SUM(yj-(1/(c1*c2))*(c3-asinh(sinh(c3)*exp(c1*j*2*pi))))^2
>
> yj is consecutive timings for a tennis ball, on a string revolving
> around a pole (the ball cannot change height)
>
> I have found some help with this:
>
> x = [ 1,2,3,4,5 ];
>
> y = [ 2.2, 1.9, 1.7, 1.5, 1.4];
>
> a11 = sum(x.^2); a12 = sum(x); a21 = sum(x); a22 = sum(ones(1,length(x)));
>
> A = [ a11,a12; a21,a22] % the coefficient matrix of the minimization
> problem
> c1 = 1;
> c2 = 1;
> c3 = 1;
> diff_c1 =
> (c3-asinh(exp(2*pi*x.*c1).*sinh(c3)))/(c1^2*c2)+(2*x.*pi*exp(2*c1*x.*pi).*sinh(c3)*asinh(exp(2*c1*x.*pi).*sinh(c3)))/(c1*c2)
>
> diff_c2 = (c3-asinh(exp(2*c1*x.*pi).*sinh(c3)))/(c1*c2^2)
> diff_c3 =
> (exp(2*c1*x.*pi).*cosh(c2)*asinh(exp(2*c1*x.*pi).*sinh(c3))-1)/(c1*c2)
> b1 = sum(diff_c1*y); b2 = sum(diff_c2*y); b3 = sum(diff_c3*y);
>
> b = [ b1; b2; b3 ] % right-hand-side of the minimization problem
>
> c = A \ b % solution of the minimization problem
>
> xApr = 0 : 0.001 : 1; yApr = c(1)*xApr + c(2);
>
> plot(x,y,'*g',xApr,yApr,'b');
> Basically diff_c1,c2,c3 are the parts multiplied by the data values yj
> for least squares minimization, i think this is correct. b1,2,3 are
> these multiples.
>
> I think the problem is I haven't got my '.''s in the correct place. I
> know that they are required to say do this for all x and y's but Im not
> sure exactly where they are required.
>
> I have posted this here because I would also appreciate some help as to
> whether I am doing this the correct way - because I also require initial
> values of c1,2,3 which i have stated as 1 but again I am not sure if I
> have done that correctly

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us