Question

In: Mechanical Engineering

For the following, explain what each of them will do in MatLab by saying what the...

For the following, explain what each of them will do in MatLab by saying what the command does and what the result is. For example, if the command is >>x(2:end, 1:3) then your answer to this problem should be: This command retrieves the subset of x defined by rows 2 and 3 and columns 1-3. The result is a 2x3 matrix. Before you begin, run the command: x = [1 3 4 5 7; 5 6 10 9 11; 10 23 23 1 3];

a) x(:,5)

b) x(1,:)

c) x(2,3:4)

d) x(1:2,2:5)

e) length(x(1,:))

f) length(x(:,1))

g) sum(x(2,:))

h) mean(x(:,end))

i) max(x)

j) max(max(x))

k) round(3.75)

l) floor(3.75)

m) rem(150,100)

n) log(25)

Solutions

Expert Solution

a):

x(:,5): This command retrieves all the elements in 5th column of the x. The result is a 3x1 matrix.

The output in command window is:

7

11

3

b):

x(1,:): This command retrieves all the elements in 1st row of the x. The result is a 1x5 matrix.

The output in command window is:

1 3 4 5 7

c):

x(2,3:4): This command retrieves all the elements in 2nd row and 3rd and 4th columns of the x. The result is a 1x2 matrix.

The output in command window is:

10 9

d):

x(1:2,2:5): This command retrieves all the elements from 1st to 2nd rows and from 2nd to 5th columns of the x. The result is a 2x4 matrix.

The output in command window is:

3 4 5 7

6 10 9 11

e):

length(x(1,:)): This command gives the length of first row of x. In other words, it gives the number of columns of x.

The output in command window is:

5

f):

length(x(:,1)): This command gives the length of first column of x. In other words, it gives the number of rows of x.

The output in command window is:

3

g):

sum(x(2,:)): This command gives the sum of all elements in second row of x.

The output in command window is:

41

h):

mean(x(:,end)): this gives the mean value of all the elements of the last column of x. It is the sum of all elements in the last row divided by number of elements in last row, i.e., (7+11+3)/3 = 7

The output in the command window is:

7.

i):

max(x): This command gives a row vector with the maximum elements in each of the columns of x. Since x has 5 columns, the size of the output vector is 1x5

The output in the command window is:

10 23 23 9 11

j):

max(max(x)): This command gives the maximum value among the maximum elements in each of the columns of x. In other words, it gives the value of the maximum element of x.

The output in the command window is:

23

k):

round(3.75): This command gives the closest integer value to the given value. In this case the closest integer is 4. If the fraction part is 0.5, for the positive number it gives the next highest integer and in case of a negative number, it gives next lowest integer.

The output in the command window is:

4

l):

floor(3.75): This command gives the closest integer value tha is less than the given value. In this case the closest integer is 3. In other words, it rounds off the given number towards negative infinity.

The output in the command window is:

3

m):

rem(150,100): This command gives the remainder obtained when the first argument is divided by the second argument. In this case, it is 50.

The output in the command window is:

50

n):

log(25): This command gives the natural logarithamic value of the input argument, i.e.,

In this case it is

The output in the command window is:

3.2189


Related Solutions

Explain why following the​ saying, "When in​ Rome, do as the Romans​ do," is appropriate to...
Explain why following the​ saying, "When in​ Rome, do as the Romans​ do," is appropriate to the negotiation process.
Use a figure and words to explain the following: What is meant by saying that a...
Use a figure and words to explain the following: What is meant by saying that a country’s exchange rate is overvalued? Also briefly state: (a) Why should it be surprising to find that a country trying to protect its domestic industries from import competition has an overvalued exchange rate? (b) Why did countries following import substitute industrialization policies nonetheless often have overvalued exchange rates?
What are the data quality dimensions? Explain each of them.
What are the data quality dimensions? Explain each of them.
What are the tools of protectionism? Explain each of them briefly.
What are the tools of protectionism? Explain each of them briefly.
What do NER and BER stand for, what kind of damage do each of them repairs?...
What do NER and BER stand for, what kind of damage do each of them repairs? Briefly, how do they repair the damage?
What are the service lines within Big 4, and what do each one of them do?
What are the service lines within Big 4, and what do each one of them do?
What are the basic sources of unemployment? Explain each of them briefly!
What are the basic sources of unemployment? Explain each of them briefly!
Explain what is meant by saying that the Model of Perfect Competition is: A description of...
Explain what is meant by saying that the Model of Perfect Competition is: A description of reality, and: A standard of comparison by which we judge industries in the economy.
describe the main purposes for this performance management system, and then explain each step by saying...
describe the main purposes for this performance management system, and then explain each step by saying who evaluates it, how often each step occurs, and what the results are.
If you disagree with what everyone else in the group is saying, what should you do?...
If you disagree with what everyone else in the group is saying, what should you do? In this week’s notes, the seven steps of the reflective thinking method are provided. Choose a problem and outline how to solve the problem, using the seven steps. 1. define the problem 2. analyze the problem 3. establish criteria for evaluating a solution 4. generate possible solutions (brainstorming) 5. choose the best solution 6. implement the solution 7. evaluate the solution
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT