Why am I getting error in event function for impulsive differential equations?
4 ビュー (過去 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!