How to plot an equation at a certain variable value?

10 Ansichten (letzte 30 Tage)
Azal Adeel
Azal Adeel am 14 Feb. 2020
Kommentiert: Star Strider am 14 Feb. 2020
%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.

Akzeptierte Antwort

Star Strider
Star Strider am 14 Feb. 2020
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 Kommentare
Star Strider
Star Strider am 14 Feb. 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by