How to speed up the while loop?

조회 수: 7 (최근 30일)
Anjani
Anjani 2021년 9월 12일
댓글: per isakson 2021년 9월 12일
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일
편집: 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일
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개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by