Results 1 to 2 of 2

Math Help - Complexity of MATLAB while loops

  1. #1
    Newbie
    Joined
    Oct 2010
    Posts
    16

    Complexity of MATLAB while loops

    Hi all,

    I've written an algorithm in MATLAB that uses a while loop to calculate a sequence a(n) given inputs u and v:

    Code:
    while u ~= a(n)*v
        t = u;
        u = v;
        v = t - a(n) * v;
        n = n + 1;
        a(n) = idivide(u, v, 'floor');
    end
    How would I go about estimating the complexity in terms of u and v? So far I've said that each iteration takes 9 operations (or 10 depending on idivide, but a constant nonetheless) so the algorithm is O(N) where N is the number of iterations, but I can't see how N depends on u and v, and I'm not even sure this is correct. I've also tried contour-plotting the running times, which is pretty, but it still just seems random.

    If it helps, the code is used to produce partial quotients for the number u/v. Given the relationship to Euclid's algorithm, I'd expect something a little worse than O(n^2) for n-digit u and v?

    Thanks in advance!
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Sep 2012
    From
    usa
    Posts
    1

    Re: Complexity of MATLAB while loops

    ??? Undefined function or variable "u". this is what the display on the matlab,have u desloved it ?
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. loops in matlab, plotting matrix elements
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 10th 2011, 09:50 AM
  2. Need help with Matlab (Loops)
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 8th 2011, 12:50 AM
  3. matlab for loops?
    Posted in the Math Software Forum
    Replies: 5
    Last Post: February 28th 2010, 09:49 PM
  4. [SOLVED] Matlab plotting help:peicewise with loops
    Posted in the Math Software Forum
    Replies: 4
    Last Post: October 20th 2009, 09:19 PM
  5. Matlab - Determining the complexity of an algorithm
    Posted in the Math Software Forum
    Replies: 5
    Last Post: March 19th 2009, 03:25 AM

Search Tags


/mathhelpforum @mathhelpforum