Finding the maximum of the constrained function

I have the function $f(a)=-(a - \beta)^2 + 8$ with constraints $a \leq$ 0$ and $a \geq 8$. I want to use *if* statements to calculate the constrained maximum and want to plot the solution in a graph, i.e, the solution should be a point on the graph of the function.

So far I have the graph of the function with the following code:

    beta = -0.5;
    a = linspace(-3,7);
    f = @(a) 8 - (a - beta).^2;
    amin = 0
    amax = 8
    figure
    plot(a,f(a))
    axis([-3 10 0 10])
    hold on
    plot(amin,f(a))
    plot(amax,f(a))

I also want to draw vertical lines of the constrains at $a=0$ and $a=8$ going all the way to $f(a)=10$. How do I do that?

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

提问:

2014-9-7

Community Treasure Hunt

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

Start Hunting!

Translated by