Can I generate a variable function for varying amounts of variables?

조회 수: 3 (최근 30일)
Louis Alen
Louis Alen 2020년 8월 27일
답변: Abdolkarim Mohammadi 2020년 8월 27일
Hello,
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))...
+abs(xF(2)*edge^3/(3*E*I)-(d(2)-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.
Kind regards,
Louis
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 8월 27일
Have you looked at Problem Based Optimization?
Louis Alen
Louis Alen 2020년 8월 27일
No I haven't, I am unfamiliar with the variety of tools. I will take a look!

댓글을 달려면 로그인하십시오.

답변 (1개)

Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020년 8월 27일
In order to achieve scalability in optimization problems or elsewhere, you should use write a general equation for your equations. For example, instead of xF(1)+xF(2) you should write sum(xF,2). The former works only for the special case of N=2, but the latter works for any value of N. Similarly, for your last sentence, I think it is a cumulative sum, which is implemented via cumsum() in MATLAB. In addition, I think using m-file functions are easier to write than inline anonymous function. You can break your equation into multiple parts, which can help write complex formulae accurately.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by