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
Use of string variables: The Characters involve letters of the alphabet, punctuation marks, digits, white space, and control characters. The Control characters are characters

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

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 nested function: The output arguments are distinct from variables. The scope of an output argument is merely the nested function; and it cannot be used in the

Types of User-defined Functions: We know how to write a user-defined function, stored in an M-file, which computes and returns one value. This is merely one type of the functi

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

Built-in function for Differentiation: The MATLAB has a built-in function, diff that returns the differences between consecutive elements in a vector. For illustration, >>

Plot types: Besides plot and bar, there are another plot types like stem plots, histograms, stem plots, area plots and pie charts, and also other functions which customize the

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

Dimensions - matrix: The size and length functions in the MATLAB are used to find array dimensions. Length function returns the number of elements in the vector. The size func