필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Rakesh
Rakesh 2022년 6월 13일
편집: Torsten 2022년 6월 14일
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
Torsten
Torsten 2022년 6월 13일
From the code I see, "te" seems to be undefined when you first call ode45.
Rakesh
Rakesh 2022년 6월 13일
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)]);

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2022년 6월 13일
https://www.mathworks.com/help/matlab/ref/ddeset.html
InitialY is only for Delay Differential Equations using ddeset()
  댓글 수: 2
Rakesh
Rakesh 2022년 6월 14일
Thank for your answer. What can I use for odeset() in place of InitialY?
Torsten
Torsten 2022년 6월 14일
편집: Torsten 2022년 6월 14일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by