a function including a constraint condition
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a function. for example f(x)=x^3+3*x^2+g(x) and g(x)=7*x+5
I have my own special algorithm in order to minimize the function f(x),so it takes lots of different x values in the algorithm loop.
I have a constraint condition: "g(x) must be always less than zero, if it is not less than zero,then do not evaluate the function f(x) until g(x) takes a negative value."
my question is: "how can i write this constraint condition with logical oparators or with an 'if-else' or 'for-else' or etc. in order not to evaluate f(x) in the loop if the constraint condition is not satisfied? so my special algorithm will search for new x values in the loop until satisfy the constraint condition."
thank you.
0 Kommentare
Antworten (2)
KSSV
am 17 Mai 2017
g = @(x) 7*x+5 ;
f = @(x) x.^3+3*x.^2+g(x) ;
% g will be negative for these values of x
x = linspace(-5/7,-10) ; % shoul dstart from -5/7 and end at inf
g = g(x) ;
f = f(x) ;
0 Kommentare
Torsten
am 17 Mai 2017
if g(x) <= 0
fval = f(x);
end % evaluate f only if g(x) <=0.
Best wishes
Torsten.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!