How to speed up the while loop?

5 views (last 30 days)
Anjani on 12 Sep 2021
Commented: per isakson on 12 Sep 2021
I have this while loop in the matlab when I try to run the code it is taking forver to run it.
Anjani on 12 Sep 2021
I have uplaoded the text file of the code. So basically we had to create the subroutine files to calculate the A and B matrix and the Force as 2x1 vector

Sign in to comment.

Accepted Answer

per isakson
per isakson on 12 Sep 2021
You didn't test the code before uploading!
I modified the input lines
z = 1; % input('Enter zeta, z = ');
w = 1; % input('Enter omega, w = ');
dt = 0.1; % input('Enter delta_t,dt = ');
Tmax = 10; % input('Enter T_max, Tmax = ');
t_i = t;
before the while-loop. And commented out
% Excit;
since it only contained comments. And modified the last statement in the while-loop
t_i = t_i+dt;
Now it runs in no time
>> tic, main, toc
Elapsed time is 0.005256 seconds.
per isakson
per isakson on 12 Sep 2021
"w,z, and dt in the command line" I guess that means you should convert the script to a function, see Scripts vs. Functions.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!