Skip to content

Commit 97a6922

Browse files
committed
backup before deleting tests and updating dates
1 parent 96e1350 commit 97a6922

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

toolbox/ivpsolver/solve_ivp.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@
7878

7979
% defines condition function
8080
if (tf > t0)
81-
C = @(t,y) t <= tf;
81+
C = @(t,y) t-h <= tf;
8282
else
83-
C = @(t,y) t >= tf;
83+
C = @(t,y) t-h >= tf;
8484
end
8585

8686
% indicates that final time is known
@@ -293,24 +293,30 @@
293293
% -----------------
294294
% Final formatting.
295295
% -----------------
296-
%n=n+1;
296+
297297
% trims arrays
298298
y = y(:,1:(n-1));
299299
t = t(1:(n-1));
300300

301+
% number of subintervals
302+
N = length(t)-1;
303+
301304
% linearly interpolates to find solution at desired final time
302305
if final_time_known
303306

304-
% number of subintervals
305-
N = length(t)-1;
306-
307307
% linearly interpolates for solution at tf
308308
y(:,N+1) = y(:,N)+((y(:,N+1)-y(:,N))/(t(N+1)-t(N)))*(tf-t(N));
309309

310310
% replaces last element of "t" with tf
311311
t(N+1) = tf;
312312

313313
end
314+
315+
% deletes penultimate solution if at same time as last solution
316+
if (abs(t(N+1)-t(N)) < 1e-10)
317+
t(N) = [];
318+
y(:,N) = [];
319+
end
314320

315321
% transposes solution matrix so it is returned in "standard form"
316322
y = y.';

toolbox/ivpsolver/test1.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
y(i+1) = RK1_euler(f,t(i),y(i),h);
1313
end
1414
[t_ivp,y_ivp] = solve_ivp(f,[2,10],y2,h,'Euler');
15+
[t_ivp,y_ivp] = solve_ivp(f,[10,2],y2,h,'Euler');
1516
%max(abs(y_ivp-y))
1617
t_ivp

toolbox/ivpsolver/test2.asv

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
%%
2+
clear;clc;close all;
3+
addpath(genpath('..'));
4+
%%
5+
f = @(t,y) y;
6+
y20 = 50;
7+
[t,y] = solve_ivp(f,[20,10],y20,0.001,'ABM8');
8+
y10 = y(end)
9+
[t,y] = solve_ivp(f,[10,20],y10,0.001,'ABM8');
10+
y20 = y(end)
11+
%%
12+
f = @(t,y) y;
13+
y20 = 50;
14+
C = @(t,y) t > 10;
15+
%[t,y] = solve_ivp(f,{20,C},y20,-0.001,'ABM8');
16+
[t,y] = solve_ivp(f,[20,10],y20,0.001,'ABM8');
17+
y10 = y(end)

toolbox/ivpsolver/test2.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
f = @(t,y) y;
66
y20 = 50;
77
[t,y] = solve_ivp(f,[20,10],y20,0.001,'ABM8');
8-
y10 = y(end)
8+
y10 = y(end);
9+
t
910
[t,y] = solve_ivp(f,[10,20],y10,0.001,'ABM8');
10-
y20 = y(end)
11-
% %%
12-
% f = @(t,y) y;
13-
% y20 = 50;
14-
% C = @(t,y) t > 10;
15-
% %[t,y] = solve_ivp(f,{20,C},y20,-0.001,'ABM8');
16-
% [t,y] = solve_ivp(f,[20,10],y20,0.001,'ABM8');
17-
% y10 = y(end)
11+
y20 = y(end);
12+
%%
13+
f = @(t,y) y;
14+
y20 = 50;
15+
C = @(t,y) t > 10;
16+
%[t,y] = solve_ivp(f,{20,C},y20,-0.001,'ABM8');
17+
[t,y] = solve_ivp(f,[20,10],y20,0.001,'ABM8');
18+
y10 = y(end);

0 commit comments

Comments
 (0)