Method other than for loop?
이전 댓글 표시
My code is quite long and outputs two values called beam1 and beam2. The values of these variables are dependant on another variable labeled length.
What I want my code to do is output a length value that allows beam1-beam2<0.0001. As of now I am using a for loop to cycle through a range of different length values to output the ones that fit my criteria. However this method takes an extremely long time to run.
Do you have any suggestions that I could use instead of a for loop that might help the program take less time to run?
댓글 수: 2
Sean de Wolski
2011년 6월 17일
Don't name your variable 'length' as that is a very useful MATLAB function that you don't want to have overwritten.
Sean de Wolski
2011년 6월 17일
Other than that we're probably going to have to see the code (at least the relevant portions) to help.
채택된 답변
추가 답변 (1개)
Andrew Newell
2011년 6월 17일
0 개 추천
Your problem sounds like an optimization problem. Using the Optimization Toolbox to find the length that minimizes beam1-beam2 would probably be the best way to speed up your code.
댓글 수: 3
Derek
2011년 6월 21일
Walter Roberson
2011년 6월 21일
The Student Edition includes the Optimization Toolbox.
http://www.mathworks.com/academia/student_version/details.html
Derek
2011년 6월 21일
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!