Info

This question is closed. Reopen it to edit or answer.

How can I save 'H' using Runge-Kutta time-step in a single . mat file each day while the code will be running for six days?

1 view (last 30 days)
dt=90; % 90 seconds
tend=1:6;% for six days
time = zeros ((3600/dt)*24*tend,1);
%Runge-Kutta time step
for nt=1:tend*24*3600/dt
K = H;
d1 = dt*Chs(K,A,B,C,D);
K = H + 0.5*d1;
d2 = dt*Chs(K,A,B,C,D);
K = H + 0.5*d2;
d3 = dt*Chs(K,A,B,C,D);
K = H + d3;
d4 = dt*Chs(K,A,B,C,D);
H = H + 1/6*(d1 + 2*d2 + 2*d3 + d4);
time(nt,1) =(nt*dt)/(3600*24);
I need help on how to save H each day in single .mat file for six days while the code is running.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 3 Jun 2020
Edited: KALYAN ACHARJYA on 3 Jun 2020
Alert: I have no experience running code for six days. I also do not know the system requirements for this work. But here, based on my theoretical concept. You can stop the running execution anytime by CLTR+C. Please note I just tried to implement e the idea (ignoring the time of execution of instructions).
time=518400; %Total seconds in 6 days
dt=90;
tic
k=1;n=1;
while toc>time
%code
H(n)=
time_day=toc;
if time_day>=k*86400 %One day seconds
save(['Day' num2str(k) '.mat'],'H')
k=k+1;
n=0;
end
n=n+1;
pause(90);
end
  1 Comment
Kayode Odeyemi
Kayode Odeyemi on 7 Jun 2020
Edited: Kayode Odeyemi on 7 Jun 2020
Thanks, but it doesn't work well.
time=518400; %Total seconds in 6 days
dt=90;
tic
k=1;n=1;
while toc>time
%code
H(n)= ?? %Not clear
time_day=toc;
if time_day>=k*86400 %One day seconds
save(['Day' num2str(k) '.mat'],'H')
k=k+1;
n=0;
end
n=n+1;
pause(90);
end

Community Treasure Hunt

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

Start Hunting!