Finding the maximum point of a function

조회 수: 14 (최근 30일)
sophp
sophp 2018년 2월 1일
댓글: Star Strider 2018년 2월 2일
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?

채택된 답변

Star Strider
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
sophp
sophp 2018년 2월 2일
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 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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by