Plotting a graph with multiple constraints

조회 수: 1 (최근 30일)
Mithuisan Sutharsan
Mithuisan Sutharsan 2020년 3월 26일
댓글: Peng Li 2020년 3월 26일
Im having trouble trouble plotting a function given multiple constraints.
For example where f(x) = cos(x)
Constraints
x>=2
x<=5
I was wondering how i could plot this graph on matlab showing both the constrains given,
Thanks in Advance for your help
  댓글 수: 2
darova
darova 2020년 3월 26일
Can you show your code? Your attempts?
Mithuisan Sutharsan
Mithuisan Sutharsan 2020년 3월 26일
fun = @(x) cos(x);
x0 = [0];
A = [3 ; 5];
x = fmincon(fun,x0,A,b)
hold all
ezplot(fun);
plot(x,4-x.*sin(x))
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Peng Li
Peng Li 2020년 3월 26일
x >= 2 & x <= 5
this express will consider both constraints in. Is this what you need?
  댓글 수: 2
Mithuisan Sutharsan
Mithuisan Sutharsan 2020년 3월 26일
Hi peng, thanks for reaching out
i need help using that as constraints to graph cos(x)
Thanks
Peng Li
Peng Li 2020년 3월 26일
x = 2:.1:5;
y = cos(x);
plot(x, y);
is this what you need?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by