How to speed up the while loop?

I have this while loop in the matlab when I try to run the code it is taking forver to run it.

6 件のコメント

per isakson
per isakson 2021 年 9 月 12 日
Did you intend to write
while t_i < Tmax
rather than
while t < Tmax
Anjani
Anjani 2021 年 9 月 12 日
I tried that as well but still it takes forever to run
Matt J
Matt J 2021 年 9 月 12 日
What does the profiler say?
Anjani
Anjani 2021 年 9 月 12 日
It does not end so it hard to tell... like it keeps running and i have to stop the run.
per isakson
per isakson 2021 年 9 月 12 日
編集済み: per isakson 2021 年 9 月 12 日
You haven't provided information enough for us help. Proposal
Anjani
Anjani 2021 年 9 月 12 日
編集済み: Anjani 2021 年 9 月 12 日
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

サインインしてコメントする。

 採用された回答

per isakson
per isakson 2021 年 9 月 12 日

0 投票

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 = ');
Added
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.

2 件のコメント

Anjani
Anjani 2021 年 9 月 12 日
編集済み: Anjani 2021 年 9 月 12 日
As part of the assignemtns we have to add the values for w,z, and dt in the command line since it will change in the future. This is the first time I did the coding so I am pretty new to this game.
per isakson
per isakson 2021 年 9 月 12 日
"w,z, and dt in the command line" I guess that means you should convert the script to a function, see Scripts vs. Functions.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2021 年 9 月 12 日

コメント済み:

2021 年 9 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by