finding optimum solution

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 Kommentare

Andrew Newell
Andrew Newell am 29 Mär. 2011
If cumsum(T)==0, then isn't T==0? Or do you mean sum(T)==0?
Cora
Cora am 29 Mär. 2011
sorry, my mistake. I mean sum(T)==0

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Andrew Newell
Andrew Newell am 30 Mär. 2011

0 Stimmen

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 Kommentar

Cora
Cora am 31 Mär. 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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrew Newell
Andrew Newell am 29 Mär. 2011

0 Stimmen

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 Kommentar

Cora
Cora am 30 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by