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 Center および File ExchangeHistograms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by