How to plot an oscillator?
조회 수: 7 (최근 30일)
이전 댓글 표시
I want to plot the equations given below. Which is generally of an 3 coupled oscillators. Can anyone please tell me if I am plotting it correctly or not? Below is my code
close all; clear all; clc;
%value of constants
a1=0.2;a2=0.3;a3=0.3;
omega1=5;omega2=4;omega3=5;
G=1;C12=0.01;C13=0.02;C21=0.03;C23=0.04;C31=0.05;C32=0.06;
dt=0.01; %step size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1(1)=0.5;
y1(1)=0.5;
x2(1)=0.5;
y2(1)=0.5;
x3(1)=0.5;
y3(1)=0.5;
for i=2:1000
%Oscillator 1
x1(i) = x1(i-1) + ( a1*x1(i-1) - omega1*y1(i-1) + G*C12*( x2(i-1) - x1(i-1) ) + G*C13*( x3(i-1) - x1(i-1) ) )*dt;
y1(i) = y1(i-1) + ( a1*y1(i-1) + omega1*x1(i-1) + G*C12*( y2(i-1) - y1(i-1) ) + G*C13*( y3(i-1) - y1(i-1) ) )*dt;
%Oscillator 2
x2(i) = x2(i-1) + ( a2*x2(i-1) - omega2*y2(i-1) + G*C21*( x1(i-1) - x2(i-1) ) + G*C23*( x3(i-1) - x2(i-1) ) )*dt;
y2(i) = y2(i-1) + ( a2*y2(i-1) + omega2*x2(i-1) + G*C21*( y1(i-1) - y2(i-1) ) + G*C23*( y3(i-1) - y2(i-1) ) )*dt;
%Oscillator 3
x3(i) = x3(i-1) + ( a3*x3(i-1) - omega3*y3(i-1) + G*C31*( x1(i-1) - x3(i-1) ) + G*C32*( x2(i-1) - x3(i-1) ) )*dt;
y3(i) = y3(i-1) + ( a3*y3(i-1) + omega3*x3(i-1) + G*C31*( y1(i-1) - y3(i-1) ) + G*C32*( y2(i-1) - y3(i-1) ) )*dt;
end
plot (x1)
hold on
plot (x2)
plot (x3)
댓글 수: 0
채택된 답변
Stephan
2023년 1월 12일
You can plot it 2 ways - i dont know what is "correct" for your case... For me both are correct - depending on what you want to see:
%value of constants
a1=0.2;a2=0.3;a3=0.3;
omega1=5;omega2=4;omega3=5;
G=1;C12=0.01;C13=0.02;C21=0.03;C23=0.04;C31=0.05;C32=0.06;
dt=0.01; %step size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1(1)=0.5;
y1(1)=0.5;
x2(1)=0.5;
y2(1)=0.5;
x3(1)=0.5;
y3(1)=0.5;
for i=2:1000
%Oscillator 1
x1(i) = x1(i-1) + ( a1*x1(i-1) - omega1*y1(i-1) + G*C12*( x2(i-1) - x1(i-1) ) + G*C13*( x3(i-1) - x1(i-1) ) )*dt;
y1(i) = y1(i-1) + ( a1*y1(i-1) + omega1*x1(i-1) + G*C12*( y2(i-1) - y1(i-1) ) + G*C13*( y3(i-1) - y1(i-1) ) )*dt;
%Oscillator 2
x2(i) = x2(i-1) + ( a2*x2(i-1) - omega2*y2(i-1) + G*C21*( x1(i-1) - x2(i-1) ) + G*C23*( x3(i-1) - x2(i-1) ) )*dt;
y2(i) = y2(i-1) + ( a2*y2(i-1) + omega2*x2(i-1) + G*C21*( y1(i-1) - y2(i-1) ) + G*C23*( y3(i-1) - y2(i-1) ) )*dt;
%Oscillator 3
x3(i) = x3(i-1) + ( a3*x3(i-1) - omega3*y3(i-1) + G*C31*( x1(i-1) - x3(i-1) ) + G*C32*( x2(i-1) - x3(i-1) ) )*dt;
y3(i) = y3(i-1) + ( a3*y3(i-1) + omega3*x3(i-1) + G*C31*( y1(i-1) - y3(i-1) ) + G*C32*( y2(i-1) - y3(i-1) ) )*dt;
end
figure(1)
plot (x1)
hold on
plot (x2)
plot (x3)
figure(2)
plot (x1,y1)
hold on
plot (x2,y2)
plot (x3,y3)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!