Effacer les filtres
Effacer les filtres

Why am I getting error in event function for impulsive differential equations?

3 vues (au cours des 30 derniers jours)
Rakesh
Rakesh le 13 Juin 2022
Modifié(e) : Torsten le 14 Juin 2022
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 commentaires
Torsten
Torsten le 13 Juin 2022
From the code I see, "te" seems to be undefined when you first call ode45.
Rakesh
Rakesh le 13 Juin 2022
Thanks for your response. When I run this code then I am getting the following errors.
Error using odeset
Unrecognized property name 'InitialY'.
Error in paper_impulse (line 20)
options = odeset(options, 'InitialY', [impulse_strength*sol.y(1,end) impulse_strength*sol.y(2,end)]);

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 13 Juin 2022
https://www.mathworks.com/help/matlab/ref/ddeset.html
InitialY is only for Delay Differential Equations using ddeset()
  2 commentaires
Rakesh
Rakesh le 14 Juin 2022
Thank for your answer. What can I use for odeset() in place of InitialY?
Torsten
Torsten le 14 Juin 2022
Modifié(e) : Torsten le 14 Juin 2022
If with "InitialY" you mean "initial values for Y": it is not specified in the options structure, but as the third argument in the call to ode45.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by