Prev: Erorr:Subscript indices must either be real positive integersor logicals
Next: signal collection and real time feedback
From: Jeremy on 15 Apr 2010 18:15 Say you have a function f(x) that you wish to integrate in steps from a to b. Two ways of writing this program would be: syms x; i=1; while i<=10 I=int(f(x),i-1,i) i=i+1; end syms x; for i=1:10 I=int(f(x),i-1,i) end Obviously the while loop is more code to write, but will it effect the efficiency of the program? I'm thinking that the while loop is going to take more time to compute, can anyone confirm this? What's the advantages of using a while loop in a situation like this, if any? |