As a sense of context, I am trying to create an optimisation algorithm with the design variable being the force on a beam itself (xF) and the objective function being the absolute difference between a measured displacement (d) and the displacement caused by the force applied to the beam. In the simplest form (with only one beam element), the optimiser will optimise the tip displacement to meet the measured tip displacement by adjusting the tip load. With more beam elements, the objective function becomes difficult to write. I have it here for two beam elements:
fobj_val = @(xF) abs((xF(1)+xF(2))*edge^3/(3*E*I)-d(1))...
With 'xF' being a 2D array, 'edge' being the beam element length, 'E' and 'I' structural properties and 'd' the 2D array of the measured displacements at the locations where the forces in 'xF' are applied. The question is basically: Is it possible to write a code to automatically write the objective function for varying number of elements ('N')? In the provided objective function, 'N' would be equal to two. Due to the nature of the system, the equation is relatively structured and can be written out in a compiled equation (with summation of, etc.). Feel free to ask what more information you would require or if something is unclear.
The equation can be generally written as:
Where the second summation does not sum over all the forces, but for the first node it sums the forces at the first node (F_1), the second node all the second forces (F_1+F_2), etc. As shown in the matlab code above.