finding optimum solution

9 visualizaciones (últimos 30 días)
Cora
Cora el 29 de Mzo. de 2011
Hi everyone,
I would apprechiate help with the following matter I have the following vectors A,D,B,C,E (each size 50,1) and calculate T=-A.*((B+x)-C)+D.*E; The goal is to find constant x so that sum(T)==0. I tried fminsearch, but didn't figure out how to make it work. I would be greatful for any help. Thanks.
  2 comentarios
Andrew Newell
Andrew Newell el 29 de Mzo. de 2011
If cumsum(T)==0, then isn't T==0? Or do you mean sum(T)==0?
Cora
Cora el 29 de Mzo. de 2011
sorry, my mistake. I mean sum(T)==0

Iniciar sesión para comentar.

Respuesta aceptada

Andrew Newell
Andrew Newell el 30 de Mzo. de 2011
I'm going to rewrite your problem in vector notation. Suppose the positions are given by vectors r_i, i=1..50, and the forces by F_i, i=1..50. The coordinates of the center are r_c. Then the torque on the system is sum_i (r_i-r_c)xF_i, where the x refers to the cross product. This can be separated into two terms: sum_i (r_i x F_i) - r_c x sum_i F_i. So you need a torque function
function T = torque(r,ri,Fi)
% Add a z component (all zeros) to allow use of CROSS.
r = [r 0];
ri = [ri zeros(length(ri),1)];
Fi = [Fi zeros(length(Fi),1)];
F = sum(Fi);
T = sum(cross(ri,Fi,2))-cross(r,F,2);
T = T(3); % The torque is only nonzero perpendicular to the plane.
To run it, save the function in a file torque.m and use these commands:
ri = [B E];
Fi = [A D];
f = @(x) torque(x,ri,Fi); % create a function f(x)
r0 = [0 0]; % initial guess for the center
rc = fsolve(f,r0)
The function f is an anonymous function, which is a way of hiding the fixed parameters ri and Fi.
  1 comentario
Cora
Cora el 31 de Mzo. de 2011
Great, thanks for this solution. It seems to optimize both vertical and horizontal position, but based on your solution I wrote a simplified script that adjusts only the horizontal position. I really apprechiate your help.
f=@(x) torque_simple(x,A,D,B,E);
r0=0;
rc = fsolve(f,r0);
function T=torque_simple(r,A,D,B,E)
T=trapz(-A.*(B+r)+D.*E);

Iniciar sesión para comentar.

Más respuestas (1)

Andrew Newell
Andrew Newell el 29 de Mzo. de 2011
As defined, your problem has an infinite number of solutions. You can expand your expression to get
T=-A.*x+D.*E-A.*B+A.*C;
Thus, for any vector T,
x = (D.*E-A.*B+A.*C-T)./A;
so you could choose any components for T so that sum(T)==0 and solve this equation.
  1 comentario
Cora
Cora el 30 de Mzo. de 2011
thanks, however I'm not sure I understand your solution. Maybe I described the problem inadequately. I calculate torque based on force and distance in horizontal and vertical direction. I have 50 force vectors (A vertical, D horizontal) and 50 positions (B,E). The sum of torque over the 50 positions should be zero. Usually it’s not because I can’t determine the initial starting position in horizontal direction well enough, so I need to displace the 50 positions in horizontal direction (B) by a constant x in order to get the correct starting position that results in T==0. The value of x I’m looking for is the closest to x==0, so the smallest correction of my initial starting point.

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by