How to Calculate Squares and Cubes in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Matlab Matrix Power
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
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 :)