Determinate the maximum

9 次查看(过去 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 CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by