How to Calculate Squares and Cubes in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Matlab Matrix Power
Click For Summary
SUMMARY

The discussion focuses on calculating squares and cubes of the numbers 1, 2, and 3 using MATLAB. Participants utilize the meshgrid function to create matrices from the vectors [1 2 3] and [2 3]. The element-wise power operator .^ is then applied to generate the final matrix containing the squares and cubes of the specified numbers. This method effectively demonstrates how to manipulate matrices in MATLAB for mathematical computations.

PREREQUISITES
  • Basic understanding of MATLAB syntax and functions
  • Familiarity with the meshgrid function in MATLAB
  • Knowledge of element-wise operations in MATLAB using the .^ operator
  • Experience with vector and matrix manipulation in MATLAB
NEXT STEPS
  • Explore MATLAB's meshgrid function in detail
  • Learn about element-wise operations in MATLAB
  • Investigate advanced matrix manipulation techniques in MATLAB
  • Practice creating and using vectors for mathematical computations in MATLAB
USEFUL FOR

Students learning MATLAB, educators teaching mathematical concepts using programming, and anyone interested in performing matrix operations for mathematical calculations.

ineedhelpnow
Messages
649
Reaction score
0
We want to know the square and the cube of each of the following numbers: 1, 2 and 3. You can have MATLAB obtain these results as follows.
Create a vector [1 2 3] . Create a vector [2 3]. Use these two vectors as inputs to the meshgrid function (with the 3-element vector as the first argument), which will produce two matrices. Each of these matrices will have 2 rows and 3 columns. The first matrix will have rows that equal the first vector. The second matrix will have columns with the elements of the second vector. Use the operator .^ (element-by-element raising to a power) to generate a matrix with the desired answers. (This final matrix should have 2 rows and 3 columns.)

hi (Wave)
so here's what i did so far
Code:
x=[1 2 3];
y=[2 3];
[x,y]=meshgrid(x,y)

im lost on what to do next :o
 
Physics news on Phys.org
So you have created two matrices and have two original vectors.

Have you tried to do what the exercise told you to use? Make a couple of combinations and see how .^ work and you will soon see the answer, that is, do what your teacher want you to do :)
 

Similar threads

  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
2
Views
3K