Plotting Complex Functions in MATLAB: Understanding Period Placement

  • Context: MATLAB 
  • Thread starter Thread starter dillonmhudson
  • Start date Start date
  • Tags Tags
    Matlab Matrix
Click For Summary

Discussion Overview

The discussion revolves around plotting complex functions in MATLAB, specifically focusing on the correct placement of periods for element-wise operations in matrix calculations. It includes practical coding issues and solutions related to MATLAB syntax.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant shares a MATLAB code snippet for plotting a complex function and expresses confusion about where to place periods for element-wise operations.
  • Another participant suggests replacing standard multiplication (*) and division (/) operators with their element-wise counterparts (.* and ./) to avoid errors in matrix calculations.
  • A later reply confirms that the suggested changes resolved the initial issue, indicating successful implementation of the advice given.
  • Further clarification is provided about the importance of using element-by-element operators to prevent dimension mismatch errors in MATLAB.
  • One participant acknowledges their inexperience with MATLAB but expresses familiarity with the vectorize function mentioned.

Areas of Agreement / Disagreement

Participants generally agree on the necessity of using element-wise operators in MATLAB for matrix calculations, and the discussion reflects a collaborative effort to resolve the initial coding issue without any apparent disagreement.

Contextual Notes

Limitations: The discussion does not address potential complexities in the mathematical formulation of the complex function itself or the implications of using the vectorize function in different contexts.

Who May Find This Useful

Individuals learning MATLAB, particularly those working with complex functions and matrix operations, may find this discussion beneficial.

dillonmhudson
Messages
47
Reaction score
0
Matrix "." Help in MATLAB

Here is my code:

f=linspace(0,1000,1000);
xf=abs((1-exp(1-2*pi*f.*1i))/(2*pi*f.*1i-1)+(((exp(4*pi*f.*1i)-1)*exp(1-6*pi*f.*1i))/(2*pi*f.*1i))+(((2*pi*f.*1i-1)*exp(1-6*pi*f.*1i)+exp(1-10*1i*f.*pi))/(8*pi^2*f.^2*1i)));
func=plot(f,xf)

I just need to know where the periods need to go, I don't get what I'm doing wrong.

TIA
 
Physics news on Phys.org


Use periods in front of operators where one of the operands is a matrix if you want an element-by-element operation. It would probably be easiest just to replace every * and / with .* and ./
 


Great! Got it working, thanks for the help!
 


No problem.

When you aren't wanting to do matrix calcs, make sure to use element-by-element operators otherwise MATLAB will throw errors when trying to multiply matrices with incompatible dimensions.

There's also a built-in function that will do this for certain expressions called http://www.mathworks.com/help/techdoc/ref/vectorize.html".
 
Last edited by a moderator:


Ok, quite the noob with MATLAB right now. I have heard of vectorize though! Thanks :cool:
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K