Solving MatLab Misunderstanding: Element-by-Element and Point-wise

  • MATLAB
  • Thread starter steve2510
  • Start date
  • Tags
    Matlab
In summary, the period "." or dot operator in MatLab is used for element-by-element array multiplication. This means it multiplies arrays on an element-by-element basis rather than performing matrix multiplication. It is necessary to use the dot operator when performing array multiplication and leaving it out results in matrix multiplication.
  • #1
steve2510
36
0
I'm current learning MatLab before i start my second year of engineering and i don't really understand a fundamental aspect of it. My problem is the use of the period "." and when it is deemed to be necessary.

I've looked up what this operator does and found definitions such as Element by element, Point-wise, ect. My problem is these don't mean much to me, I've done work on vectors and matrices, however matrices work consisted of mostly doing practice problems so maybe i don't full understand the fundamentals of matrices. Is there anyway somebody could explain to me what the period operator actually does.

For example why are these two different
y = sqrt(t).*sin(2t);
y = sqrt(t)*sin(2t);

And
y=(3.^x)./(1+3.^x)
y=(3^x )/ (1+3^x)

Any clarification would be much appreciated, thank you.

P.S I hope this is in the right board
 
Physics news on Phys.org
  • #2
Dot multiplication .* is used to perform element-by-element array multiplication. An array is either a single row (row vector) or single column (column vector) of some values. For array-array multiplication to work, the arrays must be the same length.

Suppose, you have an array A=[3; 2; 5] which is a 3x1 array and want to multiply it by B=[6; 9; 2] which is another 3x1 array (same lengths), you tell MATLAB to do the following;
Ans=A.*B which multiplies the 2 arrays on an element-by-element basis. This means it multiplies 3x6, 2x9 and 5x2 giving a resultant arry of [18; 18; 10]

Leaving out the dot operator is for matrix multiplication which is differenet.
The 2 examples you provided don't really help to explain the purpose of the dot operator as they are just scalar x scalar examples.
 

What is the difference between element-by-element and point-wise operations in MatLab?

Element-by-element operations in MatLab perform calculations on each individual element of a matrix or array. Point-wise operations, on the other hand, perform calculations on the entire matrix or array at once.

How do I know which type of operation to use in my MatLab code?

The type of operation to use depends on the specific calculations you need to perform. If you need to perform calculations on each individual element, then element-by-element operations would be more appropriate. If you need to perform calculations on the entire matrix or array, then point-wise operations would be more efficient.

Can I mix element-by-element and point-wise operations in the same MatLab code?

Yes, it is possible to mix element-by-element and point-wise operations in the same code. However, it is important to keep track of which type of operation is being used for each calculation to avoid any misunderstandings.

Are there any limitations to using element-by-element and point-wise operations in MatLab?

Element-by-element and point-wise operations can only be performed on matrices or arrays that have the same dimensions. If the dimensions are not the same, then the code will result in an error.

Can I use element-by-element and point-wise operations to perform calculations on non-numerical data in MatLab?

No, element-by-element and point-wise operations can only be used on numerical data in MatLab. If you need to perform calculations on non-numerical data, you will need to use different functions or methods.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
951
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
505
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
963
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
Back
Top