Determinate the maximum

5 ビュー (過去 30 日間)
Igor
Igor 2012 年 2 月 10 日
回答済み: nick 2025 年 4 月 17 日
I have two functions in the same graphic. I need to calculate each maximum. Can somebody help me with the code that I need to put in the EDITOR?
I send a reduce EDITOR:
M=0.577;
mv=1000;
A=1.157*10^-5;
xg0=0.05;
w0=5.17;
wf=5.17;
beta=2/100;
alfa=0.7;
L=0.734;
g=9.81;
delta=0.5;
%Equation 1
r=@(t,y) [y(3); y(4); -xg0*w0^2*sin(wf*t)-w0^2*y(1)-2*w0*beta*y(3); 0];
[Tr,Yr]= ode45(r,[0 50],[0 0 0 0]);
%System of equations
s=@(t,y) [y(3); y(4); (-(M+mv*A*L)*xg0*w0^2*sin(wf*t)-M*w0^2*y(1)-2*M*w0*beta*y(3)-mv*A*alfa*L*((mv*A*alfa*L*((M+mv*A*L)*xg0*w0^2*sin(wf*t)+M*w0^2*y(1)+2*M*w0*beta*y(3))+(M+mv*A*L)*(-mv*A*alfa*L*xg0*w0^2*sin(wf*t)-2*mv*A*g*y(2)-(1/2)*mv*A*delta*abs(y(4))*y(4)))/(mv*A*L*(M+mv*A*L)-(mv*A*L)^2)))/(M+mv*A*L);(mv*A*alfa*L*((M+mv*A*L)*xg0*w0^2*sin(wf*t)+M*w0^2*y(1)+2*M*w0*beta*y(3))+(M+mv*A*L)*(-mv*A*alfa*L*xg0*w0^2*sin(wf*t)-2*mv*A*g*y(2)-(1/2)*mv*A*delta*abs(y(4))*y(4)))/(mv*A*L*(M+mv*A*L)-(mv*A*L)^2)];
[Ts,Ys]= ode45(s,[0 50],[0 0 0 0]);
%Graphic
plot(Ts,Ys(:,1),Tr,Yr(:,1))
% Effectiveness of the system ????
Tank's.

回答 (1 件)

nick
nick 2025 年 4 月 17 日
Hello Igor,
To find the maximum values of the functions, you can use 'max' function as shown:
M = 0.577;
mv = 1000;
A = 1.157*10^-5;
xg0 = 0.05;
w0 = 5.17;
wf = 5.17;
beta = 2/100;
alfa = 0.7;
L = 0.734;
g = 9.81;
delta = 0.5;
% Equation 1
r = @(t,y) [y(3); y(4); -xg0*w0^2*sin(wf*t)-w0^2*y(1)-2*w0*beta*y(3); 0];
[Tr, Yr] = ode45(r, [0 50], [0 0 0 0]);
% System of equations
s = @(t,y) [
y(3);
y(4);
(-(M+mv*A*L)*xg0*w0^2*sin(wf*t)-M*w0^2*y(1)-2*M*w0*beta*y(3)-mv*A*alfa*L*((mv*A*alfa*L*((M+mv*A*L)*xg0*w0^2*sin(wf*t)+M*w0^2*y(1)+2*M*w0*beta*y(3))+(M+mv*A*L)*(-mv*A*alfa*L*xg0*w0^2*sin(wf*t)-2*mv*A*g*y(2)-(1/2)*mv*A*delta*abs(y(4))*y(4)))/(mv*A*L*(M+mv*A*L)-(mv*A*L)^2)))/(M+mv*A*L);
(mv*A*alfa*L*((M+mv*A*L)*xg0*w0^2*sin(wf*t)+M*w0^2*y(1)+2*M*w0*beta*y(3))+(M+mv*A*L)*(-mv*A*alfa*L*xg0*w0^2*sin(wf*t)-2*mv*A*g*y(2)-(1/2)*mv*A*delta*abs(y(4))*y(4)))/(mv*A*L*(M+mv*A*L)-(mv*A*L)^2)
];
[Ts, Ys] = ode45(s, [0 50], [0 0 0 0]);
% Plot the results
figure;
plot(Ts, Ys(:,1), 'b', Tr, Yr(:,1), 'r');
xlabel('Time');
ylabel('Response');
legend('System of Equations', 'Equation 1');
title('Comparison of Two Systems');
grid on;
% Calculate and display the maximum values
[max_Ys, idx_Ys] = max(Ys(:,1));
[max_Yr, idx_Yr] = max(Yr(:,1));
fprintf('Maximum of System of Equations: %.4f at time %.4f\n', max_Ys, Ts(idx_Ys));
Maximum of System of Equations: 0.8537 at time 49.8877
fprintf('Maximum of Equation 1: %.4f at time %.4f\n', max_Yr, Tr(idx_Yr));
Maximum of Equation 1: 1.2369 at time 49.8116
Kindly refer to the documentation by executing the following command in MATLAB Command Window to know more about 'max' function:
doc max

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by