How to maximise the objective function with constraints and plot the solution
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ancy S G
el 26 de Feb. de 2022
Comentada: William Rose
el 17 de Mzo. de 2022
I want to maximise the objective function with respect to x
function=a*ln(1+x)+b(c-x)
subjected to constraints : x,min<=x<=x,max
given parameters are a,b,c.(Randamly I choose some values but it shows error as 'Index exceeds the number of array elements. Index must not exceed 1",how to correct this?)
Also plot the x verses function graph.
0 comentarios
Respuesta aceptada
William Rose
el 27 de Feb. de 2022
@Ancy S G, Since this is a simple function of one adjustable variable, use calculus: differentiate and solve for where the derivative is zero.
therefore
which equals zero when
.
Test if . If x_opt is NOT in that range, then the value that maximizes the function inside the range will be at one end or the other of the range, so simply evaluate both endpoints and pick the higher one.
To demonstrate that this is true, let's pick random values for a,b,c. Then we will compute x_opt and y(x_opt). Then we will plot y(x) over a range to see if we got the maximum right.
Try it.
4 comentarios
William Rose
el 1 de Mzo. de 2022
@Ancy S G, Yes. Use fminbnd() to minimize a function of one variable. See attached code.
In the script, at the bottom, I define function ancy1(x,a,b,c). In the main body of the code, I use fminbnd() to find the minimum of -ancy1() with respect to x. Then I take the negative of that, to get the maximum of +ancy1(). Results are displayed graphically and on the console. The maximum found by calculus matches the minimum found numerically.
Más respuestas (1)
William Rose
el 27 de Feb. de 2022
The routine fmincon() is good for this. The name is short for function minimization with constraints. Minimize the negative of your function in order to maximize.
2 comentarios
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!