How do I use for loop to graph this

1 回表示 (過去 30 日間)
Khoi
Khoi 2024 年 2 月 25 日
コメント済み: Voss 2024 年 2 月 26 日
I'm trying to recreate the graph above using for loop code.
I got the outline done but don't know how to plot the lines inside the curve. The for loop below is incorrect. Could anyone come up with the correct for loop for this?
hold on
plot([1,0,0,1,1],[0,0,1,1,0],'g')
x = 0:0.025:1;
y = (1. - sqrt(x)).^2;
for n=1:40
plot([n/40,0],[0,n/40],k)
end

採用された回答

Voss
Voss 2024 年 2 月 25 日
hold on
x = 0:0.025:1;
y = flip(x);
for n=1:numel(x)
plot([x(n),0],[0,y(n)],'k')
end
plot([1,0,0,1,1],[0,0,1,1,0],'g')
  5 件のコメント
Khoi
Khoi 2024 年 2 月 26 日
is there any way for me to keep this line of code and add on to it using for loop?
hold on
plot([1,0,0,1,1],[0,0,1,1,0],'g')
x = 0:0.025:1;
y = (1. - sqrt(x)).^2;
Voss
Voss 2024 年 2 月 26 日
I'm not sure what you mean, but you can plot that x and y after the other stuff, sure.
hold on
x = 0:0.025:1;
y = flip(x);
for n=1:numel(x)
plot([x(n),0],[0,y(n)],'k')
end
plot([1,0,0,1,1],[0,0,1,1,0],'g')
y = (1. - sqrt(x)).^2;
plot(x,y,'LineWidth',4)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by