Using functions with the vectors and matrices, MATLAB in Mathematics

Using Functions with the Vectors and Matrices:

As MATLAB is written to work with the vectors and matrices, the whole vector or matrix can be passed as an argument to the function. MATLAB will compute the function on every element, and return as a result the vector or matrix with similar dimensions as the original. For illustration, we could pass the vector below, vec, to the abs function in order to get the absolute value of each and every element.

>> vec = -3:4

vec =

-3    -2    -1    0    1    2    3    4

>> abs(vec)

ans =

 3    2    1    0    1    2    3    4

The original vector vec has 8 elements, and as the abs function is computed for every element, the resulting vector also has 8 elements.

This would also be the case for matrices:

>> mat = randint(2,3,[-5,5])

mat =

-5 -1  0

 3  5 -1

>> abs(mat)

ans =

5 1 0

3 5 1

Posted Date: 10/18/2012 4:33:15 AM | Location : United States

Related Discussions:- Using functions with the vectors and matrices, Assignment Help, Ask Question on Using functions with the vectors and matrices, Get Answer, Expert's Help, Using functions with the vectors and matrices Discussions

Write discussion on Using functions with the vectors and matrices
Your posts are moderated
Related Questions
Writing to Files: There are many lower level functions which can write to files. We will focus on the fprintf function that can be used to write a file and also to append to a

Common form of the switch statement: The common form of the switch statement is as shown below:   switch switch_expression   case caseexp1    action1   case cas

Referring to and Modifying the Matrix Elements: To refer to matrix elements, the row and then the column indices are given in parentheses (always the row index initially and t

Logical Vectors: The relational operators can also be used with the vectors and matrices. For illustration, let's say that there is a vector, and we want to compare each eleme

Illustration of Minimum and Maximum Value Both of these functions also return the index of the minimum or maximum value; when there is more than one occurrence, it returns the

bar and barh functions: For a matrix, the bar and barh functions will group altogether the values in each and every row. The illustration is as shown: rm = randint(2,4,[1

Illustration of Labels and prompts: The program below prompts the user for endpoints (x1, y1) and (x2, y2) of a line segment, and computes the midpoint of the line segment, th

Concatenation: The String concatenation means to join the strings altogether. Of course, as strings are merely vectors of the characters, the technique of concatenating vector

Error-checking for integers: illustrations of running this script as shown below: >> readoneint Enter an integer: 9.5 Invalid! Enter an integer: 3.6 Invalid

Standard Deviation The standard deviation is the square root of variance: The built-in function in a MATLAB for the standard deviation is known as std; the standard dev