how should I add output of both oscillator and plot it?

1 次查看(过去 30 天)
hello , i am trying to implement multiple oscillators and simulating.
how should I add output of both oscillator and plot it?
should i write dz = zeros(3,1) or dz = zeros(6,1) ?
my code is
***************
oscillator function
*****************************
function dz = myeqd(t,y,ti,xx)
dz = zeros(3,1);
mu = 0.3;
r= sqrt(y(1)^2 + y(2)^2);
K1=500;
K2 = 500;
K3 = 500 ;
F=interp1(ti,xx,t);
%osc1
dz(1)= (mu - r^2)*y(1) - y(3)*y(2) +K1*F;
dz(2) = (mu - r^2)*y(2) + y(3)*y(1);
dz(3) = (-K1*F) * (y(2)/sqrt(y(1)^2 + y(2)^2));
%osc2
dz(4)= (mu - r^2)*y(4) - y(6)*y(5) +K2*F;
dz(5) = (mu- r^2)*y(5) + y(6)*y(4);
dz(6) = (-K2*F) * (y(5)/sqrt(y(4)^2 + y(5)^2));
******************************************************
mian code
**************************************
time = 0:0.001:20;
xx = chirp(time,100,10,400);
ti=time;
[T,Y]=ode45(@(t,y) myeqd(t,y,ti,xx),time,[5;5;90]);
plot (T,Y(:,3));
********************************************

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-2-10
From your function, you should write
dz = zeros(6,1)
  1 个评论
Aniket
Aniket 2013-2-10
编辑:Aniket 2013-2-11
Thanks, and how should i add output of all oscillators.
for example the output is coming at the third vector of Y that is Y(:,3)
so should i add like this ?
e = Y(:,3) + Y(:,6);
plot (T,e)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 View and Analyze Simulation Results 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by