How to plot an equation at a certain variable value?

10 visualizzazioni (ultimi 30 giorni)
%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.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by