写一个双耦合型Duffing振子的MATLAB代码示例
时间: 2024-05-16 14:12:05 浏览: 9
Sure! Here's a MATLAB code example for a double-coupled Duffing oscillator:
```
% Set up parameters
A = 1;
B = 0.25;
C = 0.5;
D = 0.1;
w1 = 2*pi*0.8;
w2 = 2*pi*1.2;
% Set up initial conditions
x1 = 0.1;
x2 = 0.2;
v1 = 0.3;
v2 = 0.4;
% Set up time vector
t = linspace(0, 50, 1000);
% Solve the Duffing oscillator system
options = odeset('RelTol', 1e-6, 'AbsTol', 1e-9);
[t, X] = ode45(@(t,X) [X(2); -A*X(1) -B*X(2) -C*X(1)^3 + D*cos(w1*t) -C*(X(1)-X(3))^3; X(4); -A*X(3) -B*X(4) -C*X(3)^3 + D*cos(w2*t) -C*(X(3)-X(1))^3], t, [x1;v1;x2;v2], options);
% Plot the results
figure;
subplot(2,1,1);
plot(t, X(:,1), 'r-', t, X(:,3), 'b--');
xlabel('Time');
ylabel('Position');
legend('x1', 'x2');
subplot(2,1,2);
plot(X(:,1), X(:,2), 'r-',