MATLAB: Finding frequency and domain of equation using ode45

MATLABode45 frequency domain

dear all
i use following code to find answer of the following equation :
u ̈+u+u^3=0
function dydt= vdp1(t,u)
dydt=[u(2);-u(1)-((u(1))^3)];
clc
clear all
for a=0.1:0.1:0.3
[t,y]=ode45(@vdp1,[0 60],[0 a]);
hold on
plot(t,y(:,1))
end
is there any way to find frequency and domain of this equation ? i know ode 45 gives nonuniform answer but can i use interpolation to finde the maximum of domain and The intersection with the x axis
In summary i want to find exact amount of red and green dot

Best Answer

Try this:
vdp1 = @(t,u) [u(2);-u(1)-((u(1))^3)];
tv = linspace(0, 60, 5000);
a=0.1:0.1:0.3;
zci2 = @(v) find(diff(sign(v)));
for k = 1:numel(a)
[t,y]=ode45(@vdp1,tv,[0 a(k)]);
ym(:,k) = y(:,1);
lmx(:,k) = islocalmax(y(:,1));
lmn(:,k) = islocalmin(y(:,1));
zx2(:,k) = find(diff(sign(y(:,1))));
end
figure
for k = 1:3
subplot(3,1,k)
plot(t,ym(:,k))
hold on
plot(t(lmx(:,k)),ym(lmx(:,k),k), '^r') % Plot Maxima
plot(t(lmn(:,k)),ym(lmn(:,k),k), 'vg') % Plot Minima
plot(t(zx2(:,k)),ym(zx2(:,k),k), 'dk') % Plot Zero-Crossings
hold off
grid
end
producing:
Related Question