Why am I getting error in event function for impulsive differential equations?
1 次查看(过去 30 天)
显示 更早的评论
function sol = paper_impulse
t0 = 0; t1 = 5;
impcount = 0; te=1; k=1; No = 1; ep=0.01; vec = []; x = []; i=0; impulse_strength = 1.2;
v=zeros(201);
while(i<5)
i = i+0.01;
x = [x, i];
end
disp(x)
x= round(x*100)/100;
while true
if (impcount ==0)
options = odeset('Events',@events,'AbsTol',1e-5,'RelTol',1e-5);
sol = ode45(@neural_network, [t0, t1], [3 5], options);
else
% Specify the new solution at impulse times...
options = odeset(options,'InitialY',[impulse_strength*sol.y(1,end) impulse_strength*sol.y(2,end)]);
sol = ode45(@neural_network, [t0, t1], sol, options);
end
t0 = sol.x(end);
fprintf('Restart at %5.2f.\n',t0);
vec = [vec,te];
ind = find(abs(x-te)<0.001);
v(ind) = v(ind) + impulse_strength;
fprintf('Restart at %5.2f.\n',ind);
k=k+1;
if(mod(k,No) == 0)
te = te+ No*(0.02-ep)+ep;
else
te = te+ ep;
end
impcount = impcount + 1;
if (t0 >= t1)
break;
end
end
plot(sol.x, sol.y(1,:));
hold on
plot(sol.x, sol.y(2,:));
%disp(size(vec));
%stem(vec, v);
%axis([1 5 0 impulse_strength*2]);
%xlabel('time');
%ylabel('impulse strength');
function dy = neural_network(t,y)
dy = zeros(2,1);
dy(1) = -1/2*y(1)-y(1).^3+y(1).*y(2).^2-((y(1).^2+y(2).^2).^1/4).*sign(y(1));
dy(2) = -1/2*y(2)-y(2).^3-y(2).*y(1).^2-((y(1).^2+y(2).^2).^1/4).*sign(y(2));
end
function [value,isterminal,direction] = events(t,y)
value = t-te;
isterminal = 1;
direction = 0;
end
end
The above code is for impulsive differential equation. I have used the event function to locate the moments at which the solution has jump kind of discontinuites. But code is compiling with errors. Please help to short out this problem.
2 个评论
回答(1 个)
Walter Roberson
2022-6-13
https://www.mathworks.com/help/matlab/ref/ddeset.html
InitialY is only for Delay Differential Equations using ddeset()
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!