Objective Function must return a scalar value.

조회 수: 2 (최근 30일)
Richard
Richard 2020년 3월 7일
댓글: Walter Roberson 2020년 3월 29일
Dear friends,
I am trying to do an optimization for a function using a "fmincon" function. I have got an error and couldn't find the problem.
The following is the error obtained :
Error using fmincon (line 609)
Supplied objective function must return a scalar value.
Error in Topo_3D (line 31)
[x,fval,ef,output,lambda,hessian] = fmincon(objective,x0,A,b,Aeq,beq,lb,ub,nonlincon,options);
A copy of my fmincon function is attached.
I appreciate if somebody help with this issue and how can be solved.
Thank you very much.
RTFQ

채택된 답변

Walter Roberson
Walter Roberson 2020년 3월 7일
f = nf*'u';
That multiplies the column vector nf by the literal character lower-case U. The 'u' will be converted to the character position that is used to encode 'u' which happens to be 117. So the vector nf is multiplied by the scalar 117 which yields a vector. However the first output of the objective function must be a scalar.
Your code happens to ignore the content of the variable you assigned, namely u
Perhaps you want nf*u' if u is a column vector the same length as nf
  댓글 수: 9
Richard
Richard 2020년 3월 29일
Mr Walter,
May I know how do I transform this into a 3D plot for:
I have x,y,z for my nodes. It was imported from Opensees.exe.
function plottruss = truss(x)
[node, elem, L] = nodelem(); % Get node and element list
% multiplication factor for area (to be adjusted)
mult = 10^3;
% plot the truss
Nel = size(elem,1);
figure(2);
plot(node(:,1),node(:,2),'k.')
hold on; axis equal;
for iel = 1:Nel
elnodes = elem(iel, 1:2);
nodexy = node(elnodes, :);
plot3(nodexy(:,1), nodexy(:,2), repmat(x(iel), size(nodexy,1), 1))
end
end
end
Thanks.
Walter Roberson
Walter Roberson 2020년 3월 29일
As far as I can tell from the code that you posted earlier, there is no z coordinate in the truss file. It is, though, possible that the data exists in the file somewhere but is not read in. I do not have documentation on the file format.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structural Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by