How to find the x and y values at the max of a curve?

1 回表示 (過去 30 日間)
Will Jeter
Will Jeter 2020 年 10 月 27 日
回答済み: Walter Roberson 2020 年 10 月 27 日
Im trying to find the max Concentration for the curve R and its corresponding time. The max function doesn't seem to work when I tried it.
function CBE350HW10PT1
tspan = [0,2000];
conc = [0.02,0,0];
[t, c] = ode45(@odefun3,tspan,conc);
figure
plot(t,c)
xlabel('Time')
ylabel('Concentration')
legend('A','R','S')
end
function dCdt = odefun3(t,c)
k1 = 0.00108;
k2 = 0.00119;
k3 = 0.00159;
CA = c(1);
CR = c(2);
CS = c(3);
dCdt = zeros(3,1);
dCdt(1) = -k1*CA;
dCdt(2) = (k1*CA)-(k2*CR)-(k3*CR*CS);
dCdt(3) = (k2*CR)-(k3*CR*CS);
end

採用された回答

Walter Roberson
Walter Roberson 2020 年 10 月 27 日
CBE350HW10PT1 %invoke the function
Maximum concentration R was 0.00698723 at time = 855.82
function CBE350HW10PT1
tspan = [0,2000];
conc = [0.02,0,0];
[t, c] = ode45(@odefun3,tspan,conc);
figure
plot(t,c)
xlabel('Time')
ylabel('Concentration')
legend('A','R','S')
[maxr, maxridx] = max(c(:,2));
maxr_t = t(maxridx);
hold on
plot(maxr_t, maxr, 'r*');
hold off
fprintf('Maximum concentration R was %g at time = %g\n', maxr, maxr_t);
end
function dCdt = odefun3(t,c)
k1 = 0.00108;
k2 = 0.00119;
k3 = 0.00159;
CA = c(1);
CR = c(2);
CS = c(3);
dCdt = zeros(3,1);
dCdt(1) = -k1*CA;
dCdt(2) = (k1*CA)-(k2*CR)-(k3*CR*CS);
dCdt(3) = (k2*CR)-(k3*CR*CS);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by