How can I change the output of the code to scalar?

조회 수: 4 (최근 30일)
Peter Mwangi
Peter Mwangi 2018년 2월 12일
답변: Peter Mwangi 2018년 2월 15일
I am trying to find the optimal values of a function @poweroptone but the GA tool doesn't complete the optimization because of the vector error. To be precise, this is the error that pops up `Error running optimization. Your fitness function must return a scalar value.` Here is the code:
function Pmax = poweroptone(Lt, R)
Lt =(0.01:0.0005:0.07);
R=(4:0.025:7);
Pmax =((1222.714521).*sqrt(Lt).*sqrt(0.03 + Lt./2).*sqrt(R./(R - 1)).*((sqrt(0.27) - 1.054.*sqrt(0.03 + Lt))./(sqrt(0.27).*(sqrt(0.03 - Lt)))));
end
The number of variables are two (2). How can I change the output of the code to scalar?
  댓글 수: 4
Peter Mwangi
Peter Mwangi 2018년 2월 12일
Thank you. Then what should I do to fix the problem?
Peter Mwangi
Peter Mwangi 2018년 2월 12일
I am trying to find the minimum value of Pmax for specific one value pf Lt and R

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

채택된 답변

Peter Mwangi
Peter Mwangi 2018년 2월 15일
Thank you for the feedback. I found the solution to the question. I first created the objective function
function P = power_one(x)
P=(1222.714521).*(sqrt(x(1))*sqrt(0.03 + (x(1))/2)*sqrt ((x(2))/((x(2) - 1)))*((sqrt(0.27) - 1.054 * sqrt(0.03 + x(1)))/(sqrt(0.27)*sqrt(0.03 + x(1)))));
end
And then I called it in the main function as follows;
Lb=[0.01 4];
Ub=[0.07 7];
fitn =@(x)power_one(x);
[x, fval]=ga(fitn,2, [], [], [], [], Lb, Ub);
I hope this will help someone in future. Thank you for the input.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by