MATLAB Lesson 9.3 - Efficiency

Поділитися
Вставка
  • Опубліковано 6 жов 2020
  • Now that I’ve introduced decision making and looping structures, we can start doing some fairly sophisticated programming. Usually this includes a LOT of calculations, which can become very time consuming. So, one facet of numerical analysis is to create code that provides results in a reasonable amount of time.
    Support us on Patreon: / hvu

КОМЕНТАРІ • 3

  • @sadiq114
    @sadiq114 3 роки тому +2

    Very good and very informative lecture. But my question is that is vectorization possible only when the elements of the array are already known or it can be applied to the array whose elements are not known in advance. Lets say for example I have u=[1 2 3 4 5 6]. I want to subtract elements of another vector two from it which is also of same size as u, i.e.
    Error=u-two;
    Now two is not a single vector. We have 100 such vectors. But we don't know elements of all two's. So I usually do like this:
    dim=6;
    two=zeros(100,dim); % Pre-Allocate space for 100 vectors of size dim in memory
    nn=0;
    for n=1:100 %------------(2)
    nn=nn+1;
    [best,fmin,time]=fpa(10,0.8,10000,dim,[0 0 0 0],[10 10 pi pi]); % algorithm returns us vector best stored in two as:
    two(nn,:)=best;
    Error(nn,:)= abs(u(1,:)-two(nn,:)); % Error between u and two
    end
    %%%%%%%%%%%%%%%% End %%%%%%%%%%%%%%%%%%
    Can we convert it into vectorization?
    Regards

    • @hanshawvirtualuniversity3114
      @hanshawvirtualuniversity3114  3 роки тому +1

      Hiya! I think the "fpa" function is the key to vectorizing this code. ("fpa" doesn't seem to be a built-in function , or at least it's not one I'm familiar with.) So it *seems* like vectorizing the code would depend on vectorizing whatever is going on in "fpa". Does that make sense?

    • @sadiq114
      @sadiq114 3 роки тому +1

      @@hanshawvirtualuniversity3114 fpa is a metaheuristic algorithm. It stands for Flower Pollination Algorithm. It randomly generates vectors of the same size as u and sends one by one from those generated vectors to the fitness function. So the random vectors generated by this algorithm are stored in two as you can see.