I got the problem with polyshape, please help me

14 ビュー (過去 30 日間)
Thai Anh
Thai Anh 2022 年 12 月 4 日
編集済み: Stephan 2022 年 12 月 5 日
Demand: sketch the domain D be the region bounded by
My code:
x1 = 0:1:30;
y1 = 2-x1;
y2 = sqrt(x1).*(12-x1)./2;
xcut = fzero(@(x)sqrt(x).*(12-x)./2 - 2+x, 0.5);
x = [x1(x1<=xcut), x1(end)];
y = [sqrt(x1).*(12-x1)./2 (x1<=xcut), 2-x1(end)];
M = polyshape(x,y);
plot(x1,y1,x1,y2,x,y)
hold on
plot(M)
hold off
xlim([0,30])
ylim([0,30])
Error:
Error using polyshape/getXY
x- and y-coordinates must be vectors of the same size with at least 3 elements.
Error in polyshape/checkInput (line 842)
[X, Y, xy2input, next_arg] = polyshape.getXY(varargin{:});
Error in polyshape (line 169)
[X, Y, tc, simpl, collinear] = polyshape.checkInput(param, varargin{:});
Error in bai4 (line 7)
M = polyshape(x,y);
  4 件のコメント
Thai Anh
Thai Anh 2022 年 12 月 4 日
@John D'Errico can you help me to fix it
Thai Anh
Thai Anh 2022 年 12 月 4 日
oh I'm sorry.
The demand is sketch the domain D be the region bounded by

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

採用された回答

Stephan
Stephan 2022 年 12 月 4 日
You have to take both points into account to find a closed region:
xcut1 = fzero(@(x)sqrt(x).*(12-x)./2 - 2+x, 0.5);
xcut2 = fzero(@(x)sqrt(x).*(12-x)./2 - 2+x, 20);
I had the code ready here - but homework is homework... I leave the rest to you. It should be easy now...
  12 件のコメント
Thai Anh
Thai Anh 2022 年 12 月 5 日
x1 = 0:1:30;
y1 = 2-x1;
y2 = sqrt(x1).*(12-x1)./2;
xcut1 = fzero(@(x)sqrt(x).*(12-x)./2 - 2+x, 0.5);
xcut2 = fzero(@(x)sqrt(x).*(12-x)./2 - 2+x, 20);
a=[x1(xcut1<=x1),x1(x1<=xcut2)];
b=[2-x1 (x1>=xcut1), 2-x1 (x1<=xcut2)] ;
M = polyshape(a,b);
plot(M)
hold on;
grid on;
xlim([0,30])
ylim([0,30])
..... I tried but I cannot mark the curve region
Stephan
Stephan 2022 年 12 月 5 日
編集済み: Stephan 2022 年 12 月 5 日
Sorry, last try - i can not make it more clear without doing your homework:
x = -10:1:10;
y1 = -x.^2 + 100;
y2 = 0.*x + 50;
xcut1 = fzero(@(x)-x.^2 + 100 - 50,-7);
xcut2 = fzero(@(x)-x.^2 + 100 - 50,7);
x_linear = [xcut1 xcut2];
y_linear = [50 50];
x_quad = linspace(xcut1, xcut2, 25);
y_quad = -x_quad.^2 + 100;
M = polyshape([x_linear, x_quad], [y_linear, y_quad],'simplify', false);
plot(x,y1,x,y2)
hold on
plot(M)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by