Nonlinear Constraint with Secondary Variable fmincon

조회 수: 1 (최근 30일)
Yasin GARGI 2023년 3월 14일
답변: Sai Sumanth Korthiwada 2023년 3월 27일
Hello All;
I want to use nonlinear constarint in my fmincon command, however I want to define such equation
x= optimized coefficient
b=value calculated anaother function, this value also depends on the optimized x values, it is calculated using the x values.
However , it can not get the value of 'b' from within the function and use it so gives an error.
"Unrecognized function or variable 'b'
Even though I call the function from which I get the 'b' values, it still gives the same error.
How can I solve this problem?

답변 (1개)

Sai Sumanth Korthiwada
Sai Sumanth Korthiwada 2023년 3월 27일
Hi Yasin,
As the error log suggests, " Unrecognized function or variable 'b' " describes that the variable 'b' is not yet created while the execution is in that line.
And, as you are calling a function to get the 'b' values, the 'b' values may not have returned after the function execution. Please ensure that the 'b' values are returned from the function and are stored in a global variable 'b', so that c=b*(x^2)+4 works. If 'b' is declared within a function, its scope will be within that function only. It cannot be accessed outside the function, it has to be returned to global/main. You can have breakpoints to verify whether 'b' is created while the execution is in line c=b*(x^2)+4.
Hope this answers your query!


Help CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by