what's the problem in defining the function in for loop?
Afficher commentaires plus anciens
clc
ti = 0; %inital time
tf = 70E-9;% final time
tspan=[ti tf];
tp =1E-12;
T = 2E3;
p = 0.05;
k = (0.62).*10^(4);
c = 3E8;
N = 3.0;
n = k*(c/N)*tp
a = 5;
f = @(t,y) [
(y(4).*y(1) - n.*y(2).*sin(y(3)));
(y(5).*y(2) + n.*y(1).*sin(y(3)));
(-a.*(y(5)-y(4)) + n.*((y(1)./y(2)) - (y(2)./y(1))).*cos(y(3)));
(p - y(4)-(1+2.*y(4)).*(y(1)^2))./T;
(p - y(5)-(1+2.*y(5)).*(y(2)^2))./T;
];
[time,Y] = ode45(f,tspan./tp,[sqrt(p);sqrt(p);0;0;0.01]);
O = linspace(-10,10,100);
U = zeros(length(O),1) ;
for i = 1:length(O)
U(i) = -a.*(Y(:,5) - Y(:,4)).*O(i) + n.*((Y(:,1)./Y(:,2)) - (Y(:,2)./Y(:,1)))*sin(O(i));
end
subplot 311
plot(time,Y(:,3));
xlabel('time')
ylabel('phase')
subplot 312
plot(time,Y(:,2));
xlabel('time')
ylabel('Amplitude')
subplot 312
plot(O,U);
xlabel('phase')
ylabel('potential')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
