How to plot an equation at a certain variable value?
조회 수: 10 (최근 30일)
이전 댓글 표시
%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.
댓글 수: 0
채택된 답변
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
Star Strider
2020년 2월 14일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!