Azzera filtri
Azzera filtri

Finding the maximum point of a function

4 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Star Strider
Star Strider il 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 Commenti
sophp
sophp il 2 Feb 2018
Hi Star Strider, thanks for this!! I do not think it is working as the idx1 and idx20 are claimed to be 26 and 12 respectively but this does not correspond with what is displayed on my graph (values should be about 700 and 850). Also, my mistake, the interval of t is between 2 and 20, I did change this when using MATLAB but it did not display the correct answer.
Star Strider
Star Strider il 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by