フィルターのクリア

Plotting function with differenting constant

1 回表示 (過去 30 日間)
Efrat Hazan Elimelech
Efrat Hazan Elimelech 2022 年 7 月 19 日
編集済み: Voss 2022 年 7 月 19 日
Hi,
I'm pretty unexperienced with Matlab so pls bear with me:
I'm trying to plot the function
y=a/(x+1)-(a-x)^2+x/(x+a)
when a is a vector of
a=[1,2,3,50,300]
so I put it in the loop:
for i=1:length(a)
ai=a(i);
y{i}=@(x) (ai/(x+1)-(ai-x)^2+x/(x+ai));
fplot(y{i});
end
but I get just one graph (of ai=300) and tons of yellow warnings..
any comments?

採用された回答

Voss
Voss 2022 年 7 月 19 日
a=[1,2,3];%,50,300]; % using just the first 3 a values, for this demonstration
for i=1:length(a)
ai=a(i);
% y{i}=@(x) (ai/(x+1)-(ai-x)^2+x/(x+ai));
y{i}=@(x) (ai./(x+1)-(ai-x).^2+x./(x+ai)); % using element-wise operations (./ and .^) to vectorize
fplot(y{i});
hold on % using hold on to show multiple lines at once
end
  2 件のコメント
Efrat Hazan Elimelech
Efrat Hazan Elimelech 2022 年 7 月 19 日
thanks a lot!
Voss
Voss 2022 年 7 月 19 日
編集済み: Voss 2022 年 7 月 19 日
You're welcome!

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

その他の回答 (1 件)

Torsten
Torsten 2022 年 7 月 19 日
Include the command
hold on
after the line
fplot(y{i});
such that preceeding graphs are not overwritten.

カテゴリ

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