Nonlinear constraint function error
이전 댓글 표시
Hello,
This is my first time using a genetic algorithm. I am having some issues.
This is the current error I am getting:
Error in microprocessor_ga_Sanders (line 10)
[best_X,best_Objective] =
ga(@microprocessor_cost,NVARS,[],[],[],[],lb,ub,@constraint_function_microprocessor,INTCON,options)
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
I will attach my codes and all my functions. Let me know if you have any questions.
The main code with the error is microprocessor_ga_Sanders.
댓글 수: 5
Matt J
2022년 9월 19일
It looks like you have your cost and constraint functions interchanged. Shouldn't you have,
ga(@microprocessor_cost,NVARS,...
[],[],[],[],lb,ub,@constraint_function_microprocessor,INTCON,options)
Maddie Sanders
2022년 9월 19일
Re-run your code after executing at the command line,
dbstop if caught error
Maddie Sanders
2022년 9월 19일
Maddie Sanders
2022년 9월 19일
답변 (1개)
Akshat Dalal
2023년 10월 4일
1 개 추천
Hi Maddie,
I understand you are facing an error while using a custom non-linear constraint function. I went through your code, and I believe the error is occurring because the variable ‘A_unfinned' is not declared in your custom constraint function.
I see that you have declared ‘A_unfinned’ in the ‘resistance_microprocessor’ function. However, this instance of ‘A_unfinned' cannot be used in your custom constraint function. This is because in MATLAB, each function is executed in its own personal ‘function workspace’ which is separate from the ‘base workspace’. The contents of a function’s workspace are local to that function and cannot be accessed by other functions. Thus, the variable ‘A_unfinned' declared in ‘resistance_microprocessor’ cannot be accessed in the Constraint function.
For more information on function workspace, you can refer to the following documentation - https://in.mathworks.com/help/matlab/matlab_prog/base-and-function-workspaces.html
카테고리
도움말 센터 및 File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!