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

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
Maddie Sanders 2022년 9월 19일
Yes, thank you! I actually just realized that I made this mistake. However, I am still getting an error.
Error using ga (line 393)
Unrecognized function or variable 'A_unfinned'.
Error in microprocessor_ga_Sanders (line 10)
[best_X,best_Objective] =
ga(@microprocessor_cost,NVARS,[],[],[],[],lb,ub,@Constraint_function_microprocessor_Sanders,INTCON,options)
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
Matt J
Matt J 2022년 9월 19일
편집: Matt J 2022년 9월 19일
Re-run your code after executing at the command line,
dbstop if caught error
Maddie Sanders
Maddie Sanders 2022년 9월 19일
What should be the result of doing this? I just tried doing it but am not able to get through all the code.
Maddie Sanders
Maddie Sanders 2022년 9월 19일
It seems like I am having an issue with my A_unfinned in my constraint function, but I have it in a different function and even when I defined it in the constraint function, I am still having issues.

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

답변 (1개)

Akshat Dalal
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에 대해 자세히 알아보기

질문:

2022년 9월 19일

답변:

2023년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by