Finding the maximum point of a function
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sophp
am 1 Feb. 2018
Kommentiert: Star Strider
am 2 Feb. 2018
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 Kommentare
Akzeptierte Antwort
Star Strider
am 1 Feb. 2018
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 Kommentare
Star Strider
am 2 Feb. 2018
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!