How to find the maximum value
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Below is a 3D graph.
T=600:1:850;
t=0.2:0.1:20;
[tm,Tm] = meshgrid(t, T);
k1 = 10^7.*exp(-12700./Tm);
k2 = 5*10^4.*exp(-10800./Tm);
k3 = 7*10^7.*exp(-15000./Tm);
Y_B = (k1.*tm)./(((k2.*tm)+1).*(1+(tm.*(k1+k3))));
mesh(t,T,Y_B)
view(40, 45)
grid on
How do I find the maximum value of Y_B for t=0.2:0.1:20 over the range of T from 600 to 850 and plots on a double y-axis graph the value of T and Y_Bmax with t?
0 Commenti
Risposta accettata
Jan
il 6 Feb 2018
Modificato: Jan
il 6 Feb 2018
t = 0.2:0.1:20;
T = 600:50:850;
for i = 1:numel(T)
k1 = 1e7 .* exp(-12700 ./ T(i));
k2 = 5e4 .* exp(-10800 ./ T(i));
k3 = 7e7 .* exp(-15000 ./ T(i));
for j = 1:numel(t)
Y_B(i,j) = (k1.*t(j)) ./ (((k2.*t(j))+1).*(1+(t(j).*(k1+k3))));
% Prefer:
% Y_B(i,j) = k1 .* t(j) ./ ((k2 .* t(j) + 1) .* (1 + t(j) .* (k1 + k3)));
end
end
plot(t, max(Y_B, [], 1), '.-');
k1, k2, k3 are not changed inside the inner loop, so move them to the outer one. I would not overdo it with the parentheses.
By the way, you can even omit the loops:
t = 0.2:0.1:20;
T = (600:50:850).';
k1 = 1e7 .* exp(-12700 ./ T);
k2 = 5e4 .* exp(-10800 ./ T);
k3 = 7e7 .* exp(-15000 ./ T);
Y_B = k1 .* t ./ ((k2 .* t + 1) .* (1 + t .* (k1 + k3))); % >= R2016
plot(t, max(Y_B, [], 1), '.-');
This uses auto expanding, which was introduced in Matlab R2016b. Your meshgrid approach was fine also, while the loops suggested by Birdman have no advantage here.
2 Commenti
Più risposte (1)
Rik
il 6 Feb 2018
You can specify the dimension max should operate on, so you can insert your matrix. See the documentation for instructions.
For a double y-axis, see yyaxis, or search the File Exchange for one of many examples.
Vedere anche
Categorie
Scopri di più su Discrete Data 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!