olzchatter.blogg.se

Matlab symbolic toolbox matrix multiplication
Matlab symbolic toolbox matrix multiplication





matlab symbolic toolbox matrix multiplication

I assume that you're referring to this Pochhammer function. It tends to be faster for large values of vector size or repetition factor, and slower for small values.

matlab symbolic toolbox matrix multiplication

The indexing-based approach is similar to repmat.The multiply-based approach is always slower than repmat.Some conclusions can be drawn from the figures: Title('1: repmat is fastest 2: multiply is 3: indexing is') Times = cat(3, time_repmat, time_multiply, time_indexing) Perhaps a better comparison is to indicate, for each tested vector size and repetition factor, which of the three approaches is the fastest: figure Title('Time of indexing / time of repmat') Title('Time of multiply / time of repmat') The results are plotted in the following two figures, using repmat as reference: figure Time_indexing(ind_m, ind_n) = f_indexing(vector, n)) Time_multiply(ind_m, ind_n) = f_multiply(vector, n))

matlab symbolic toolbox matrix multiplication

Time_repmat(ind_m, ind_n) = f_repmat(vector, n)) %// measure time Time_repmat = NaN(numel(M), numel(N)) %// preallocate results N = round(logspace(2,3,15)) %// repetition factors Then generate vectors of different size, and use different repetition factors: M = round(logspace(2,4,15)) %// vector sizes The results to be shown are for Matlab R2015b on Windows.įirst define a function for each of the considered approaches: %// repmat approach Here is some benchmarking using timeit with different vector sizes and repetition factors. ' and professors can tell you things that are plain wrong :-) What really got me upset is, it was my professor who had actually said that ' meant transpose! He forgot to mention the conjugate, and hence my error. For example, if you are defining a dot product for real vectors, it may be appropriate to use ', because should you want to use complex inputs in the future, the conjugate transpose would make more sense.ġ In my early Matlab days, it took me quite a while to trace back a certain problem in my code, which turned out to be caused by using ' when I should have used. Of course, if you are using real inputs but a conjugation would make sense for complex inputs, do use '. If one day in the future you apply your function to complex inputs the behaviour will suddenly change, and you will have a hard time finding the cause. As probable illustrations of this, see this question or this one.įuture-proofness. You'll get used to writing ' to transpose and will fail to notice the difference. Don't throw in an unnecessary conjugation. The mains reasons for this are:Ĭonceptual clarity: if you need to transpose, just transpose. ' when you just want to transpose, even if the numbers are real and thus ' would have the same effect. I would definitely say it's good practice to use.







Matlab symbolic toolbox matrix multiplication