How to plot an equation at a certain variable value?

9 ビュー (過去 30 日間)
Azal Adeel
Azal Adeel 2020 年 2 月 14 日
コメント済み: Star Strider 2020 年 2 月 14 日
%Setting up Variables%
Vmax=5; %Given%
K =20; %Given%
S=0:1:100; %Range of values from 0 to 100 at increments of 1%
v=(Vmax*S.^h)./(K.^h+S.^h); %Hill Equation with known variables plugged in%
plot(S,v(1)); %Plotting Hill Equation with h=1
hold on %Allowing multiple graphs to be shown%
plot(S,v(2)); %Plotting Hill Equation with h=2%
hold on %Allowing multiple graphs to be shown%
plot(s,v(10)); %Plotting Hill Equation with h=10
hold on %Allowing multiple graphs to be shown%
How would you go about plotting different h values (ie 1,2,10) and having them all on one plot? Im having trouble substituting in the h values.

採用された回答

Star Strider
Star Strider 2020 年 2 月 14 日
One approach:
Vmax=5; %Given%
K =20; %Given%
S=0:1:100; %Range of values from 0 to 100 at increments of 1%
h = [1 2 10];
for k = 1:numel(h)
v(k,:) = (Vmax*S.^h(k))./(K.^h(k)+S.^h(k)); %Hill Equation with known variables plugged in%
end
figure
plot(S,v); %Plotting Hill Equation with h=1
grid
lgnd = sprintfc('h = %3d', h); % Undocumented,‘compose’ Will Also Work Here
legend(lgnd)
A different approach (without the explicit loop) would use ndgrid or meshgrid from ‘S’ and ‘h’ and create an anonymous function from ‘v’ to calculate the resulting matrix.
  2 件のコメント
Azal Adeel
Azal Adeel 2020 年 2 月 14 日
Thank you!
Star Strider
Star Strider 2020 年 2 月 14 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by