Plotting a graph with multiple constraints

20 views (last 30 days)
Im having trouble trouble plotting a function given multiple constraints.
For example where f(x) = cos(x)
I was wondering how i could plot this graph on matlab showing both the constrains given,
Thanks in Advance for your help
Mithuisan Sutharsan
Mithuisan Sutharsan on 26 Mar 2020
fun = @(x) cos(x);
x0 = [0];
A = [3 ; 5];
x = fmincon(fun,x0,A,b)
hold all
Hi darova
Thanks for reaching out.
i tried the code above but i only get the graph of a regular cos(x)
my constraints are not shown in the plot

Sign in to comment.

Answers (1)

Peng Li
Peng Li on 26 Mar 2020
x >= 2 & x <= 5
this express will consider both constraints in. Is this what you need?
Peng Li
Peng Li on 26 Mar 2020
x = 2:.1:5;
y = cos(x);
plot(x, y);
is this what you need?

Sign in to comment.


Find more on Graph and Network Algorithms 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!

Translated by