フィルターのクリア

Using verticalRegion, but no graph appears

2 ビュー (過去 30 日間)
Cassandra Meyer
Cassandra Meyer 2022 年 4 月 30 日
コメント済み: Voss 2022 年 5 月 2 日
I am trying to use verticalRegion, with x^2 and x from 0 to 1. In an attempt to use the code given by my textbook, it says this is an invalid use of the operator. It feels like there is small mistake, but I do not know what to change. Any help would be appreciated. Thanks!
function verticalRegion(x.^2, x, 0, 1)
fplot(f, [0, 1]), hold on
fplot(g, [0, 1], 'Linewidth', 2)
xcoord = linspace(0, 1, 20);
ycoord = [f(xcoord); g(xcoord)];
plot([xcoord;xcoord], ycoord), hold off
end

採用された回答

Voss
Voss 2022 年 4 月 30 日
Try it like this:
f = @(x)x.^2;
g = @(x)x;
% calling verticalRegion
verticalRegion(f, g, 0, 1)
% defining verticalRegion
function verticalRegion(f, g, xmin, xmax)
fplot(f, [xmin, xmax]), hold on
fplot(g, [xmin, xmax], 'Linewidth', 2)
xcoord = linspace(xmin, xmax, 20);
ycoord = [f(xcoord); g(xcoord)];
plot([xcoord;xcoord], ycoord), hold off
end
  2 件のコメント
Cassandra Meyer
Cassandra Meyer 2022 年 5 月 2 日
ohhh, great thank you so much!
Voss
Voss 2022 年 5 月 2 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by