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
Illustration of a recursive function: illustration is of a recursive function which does not return anything, but simply prints. The below function prtwords receives a sentenc

Illustration of Spreadsheet Files: This reads the numbers in a double vector variable nums and the text in a cell array txt (the xlsread function forever returns the numbers f

strvcat function - concatenation: The function strvcat will concatenate it vertically, that means that it will generate a column vector of the strings.   >> strvcat(fir

Use of logical vector: Determine how many elements in the vector vec were greater than 5, the sum function can be used on the resulting vector isg: >> sum(isg) ans =

Illustration of Writing variables to a file: For illustration, in the below session in the Command Window, 3 variables are generated; these are then exhibited using who. Then,

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

Animation: In this part we will observe a couple of ways to animate a plot. These are visuals, therefore the outcomes can't really be shown here; it is essential to type these

Illustration of Empty vectors: The Empty vectors can also be used to delete elements from the arrays. For illustration, to remove the third element from array, an empty vector

Built-in functions for Complex numbers:   We know that in MATLAB both i and j are built-in functions which return √-1 (therefore, they can be thought of as built-in constants).

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