How can I optimize my MATLAB program to reduce processing time?

  • Context: MATLAB 
  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Matlab Program
Click For Summary

Discussion Overview

The discussion revolves around optimizing a MATLAB program to reduce processing time, specifically focusing on rewriting code that currently relies heavily on for loops. Participants are exploring how to express matrix computations in vector form to enhance efficiency.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant describes a MATLAB code that is slow due to extensive use of for loops and seeks assistance in converting it to a vectorized form.
  • The participant outlines the need to compute four matrices \Phi^{(i,j)} for i,j=1,2, with specific entry definitions involving complex functions and sinc functions.
  • Another participant inquires about the size of N, which is confirmed to be as large as 1024.
  • Further questions are raised regarding the definitions of variables f, C, and C*, with clarifications provided that f and C are vectors of size N-by-1 and that C* denotes the complex conjugate.
  • It is noted that a1 and a2 are arbitrary numbers, indicating flexibility in their values.

Areas of Agreement / Disagreement

There is no consensus yet on the best approach to optimize the MATLAB code, and multiple questions remain unanswered regarding the definitions of variables and the specifics of the computation.

Contextual Notes

The discussion lacks detailed definitions of the functions involved and the mathematical properties that may affect the optimization process. There are also unresolved aspects regarding the implementation of vectorization in the context of the provided equations.

Who May Find This Useful

Individuals interested in MATLAB programming, particularly those looking to optimize code performance through vectorization techniques, may find this discussion relevant.

EngWiPy
Messages
1,361
Reaction score
61
Hello,

I have a MATLAB code that contains a lot of for loops, and hence it is very slow, and takes hours and hours to get just initial results, which is very inefficient. I know writing the program in terms of vectors will fasten the process, however, I do not know how to write my program that way, and I hope one of you guys will help me.

Basically, I need to find four matrices \Phi^{(i,j)} for i,j=1,2, where each matrix is of size N-by-N. The entries are given by:

[\Phi^{(i,j)}]_{k,m}=C_i^*(f_k)C_j(f_m)\exp\left(j\pi\vartheta_{k,m}^{(i,j)}\right)sinc\left(\vartheta_{k,m}^{(i,j)}\right)

where

\vartheta_{k,m}^{(i,j)}=f_ma_i-f_ka_j+\frac{m-k}{T},\,\,\,k,m=0,1,\ldots,N-1

How can I do that in vector form, with the least number of for loops?

Thanks in advance
 
Physics news on Phys.org
How big does N get?

What are f, C, and C*?
 
Last edited:
SteamKing said:
How big does N get?

It goes as large as 1024.
 
What are f, C,and C*?
 
SteamKing said:
What are f, C,and C*?

It is enough I guess if you consider f as a vector of size N-by-1. So, C is also a vector of size N-by-1. The * means complex conjugation. Also consider a1 and a2 as any numbers, it doesn't matter.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K