Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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 Commenti
Torsten
Torsten il 13 Giu 2022
From the code I see, "te" seems to be undefined when you first call ode45.
Rakesh
Rakesh il 13 Giu 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)]);

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 13 Giu 2022
https://www.mathworks.com/help/matlab/ref/ddeset.html
InitialY is only for Delay Differential Equations using ddeset()
  2 Commenti
Rakesh
Rakesh il 14 Giu 2022
Thank for your answer. What can I use for odeset() in place of InitialY?
Torsten
Torsten il 14 Giu 2022
Modificato: Torsten il 14 Giu 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.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by