Nonlinear constraint function error
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Akshat Dalal
on 4 Oct 2023
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
0 Comments
See Also
Categories
Find more on Nonlinear Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!