How to plot an equation at a certain variable value?

6 views (last 30 days)
%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.

Accepted Answer

Star Strider
Star Strider on 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.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!