Finding the maximum point of a function
4 次查看(过去 30 天)
显示 更早的评论
I would like to find the T value and Y_B value at the maximum for t=1s and t=20s
T=600:10:850;
t = 1;
k1 = 1e7.*exp(-12700./T);
k2 = 5e4.*exp(-10800./T);
k3 = 7e7.*exp(-15000./T);
t=2:2:20;
hold on;
for i=1:numel(t)
Y_B = (k1.*t(i))./(((k2.*t(i))+1).*(1+(t(i).*(k1+k3))));
plot(T,Y_B);
xlabel('Temperature, T / K')
ylabel('Yield of Maleic Anhydride, Y_B')
legend('\tau = 2s','\tau = 4s','\tau = 6s','\tau = 8s','\tau = 10s','\tau = 12s','\tau = 14s','\tau = 16s','\tau = 18s','\tau = 20s')
end
I know how do it this when a single function is plotted, but not when several are. How do I do this?
0 个评论
采纳的回答
Star Strider
2018-2-1
Try this:
T=600:10:850;
t = 1;
k1 = 1e7.*exp(-12700./T);
k2 = 5e4.*exp(-10800./T);
k3 = 7e7.*exp(-15000./T);
t=2:2:20;
hold on;
for i=1:numel(t)
Y_B = (k1.*t(i))./(((k2.*t(i))+1).*(1+(t(i).*(k1+k3))));
plot(T,Y_B);
xlabel('Temperature, T / K')
ylabel('Yield of Maleic Anhydride, Y_B')
legend('\tau = 2s','\tau = 4s','\tau = 6s','\tau = 8s','\tau = 10s','\tau = 12s','\tau = 14s','\tau = 16s','\tau = 18s','\tau = 20s')
end
Y_B_fcn = @(t) (k1.*t)./(((k2.*t)+1).*(1+(t.*(k1+k3))));
[Y_B_max1, idx1] = max(Y_B_fcn(1)); % Maximum & Index At ‘t=1’
[Y_B_max20, idx20] = max(Y_B_fcn(20)); % Maximum & Index At ‘t=20’
Y_B_max1 =
0.48894
idx1 =
26
Y_B_max20 =
0.51129
idx20 =
12
2 个评论
Star Strider
2018-2-2
As always, my pleasure!
The ‘idx’ values are indices into ‘t’ (or ‘T’, since I am getting them confused).
The ‘T’ values corresponding to those indices are:
T_1 = T(idx1)
T_20 = T(idx20)
T_1 =
850
T_20 =
710
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!