leftimage for poohprod.ru

Tutorial Lesson: Vector Algebra (Algebra with many numbers, all at once...)

You'll learn to create arrays and vectors, and how to perform algebra and trigonometric operations on them. This is called Vector Algebra.

An array is an arbitrary list of numbers or expressions arranged in horizontal rows and vertical columns. When an array has only one row or column, it is called a vector. An array with m rows and n columns is a called a matrix of size m x n.

Launch MATLAB and reproduce the following information. You type only what you see right after the '>>' sign. MATLAB confirms what you enter, or gives an answer.

Let x be a row vector with 3 elements (spaces determine different columns). Start your vectors with '[' and end them with ']'.

>> x=[3 4 5]

x = 3 4 5

Let y be a column vector with 3 elements (use the ';' sign to separate each row). MATLAB confirms this column vector.

>> y=[3; 4; 5]

y =

You can add or subtract vectors of the same size:
>> x+x

ans = 6 8 10

>> y+y

ans =

You cannot add/subtract a row to/from a column (Matlab indicates the error). For example:

>> x+y
??? Error using ==> plus
Matrix dimensions must agree.

You can multiply or divide element-by-element of same-sized vectors
(using the '.*' or './' operators) and assign the result to a different variable vector:

>> x.*x

ans = 9 16 25

>> y./y

ans =

>> a=[1 2 3].*x

a = 3 8 15

>> b=x./[7 6 5]

b = 0.4286 0.6667 1.0000

Multiplying (or dividing) a vector with (or by) a scalar does not need any special operator (you can use just '*' or '/'):

>> c = 3*x

c = 9 12 15

>> d = y/2

d =

The instruction 'linspace' creates a vector with some elements linearly spaced between your initial and final specified numbers, for example:
r = linspace(initial_number, final_number, number_of_elements)

>> r = linspace(2,6,5)

r = 2 3 4 5 6


>> r = linspace(2,3,4)

r = 2.0000 2.3333 2.6667 3.0000

Trigonometric functions (sin, cos, tan...) and math functions (sqrt, log, exp...) operate on vectors element-by-element (angles are in radians).

>> sqrt(r)

ans = 1.4142 1.5275 1.6330 1.7321

>> cos(r)

ans = -0.4161 -0.6908 -0.8893 -0.9900

Well done!
So far, so good?

Experimenting with numbers, vectors and matrices is good for you and it does not hurt! Vector algebra can even be fun if you work with a computer and a good software, can't it?

Go on!

From 'Vector Algebra' to home

From 'Vector Algebra' to Tutorials


Next: 2D plots

footer for vector algebra page

Related pages

fibonacci series examplestriangle sum theorem calculatorsalvage value and depreciationbinary gray code conversionstrings in matlaboctal tabledefine piecewise functionhow to calculate salvage value of equipmentlagrange polynomial in matlabhow to draw a 3d cuboidmatlab gui examplematlab plot exponential functioncalculate square feet from inchesprogram on fibonacci seriesexamples of fibonacci seriesmatlab regressionfzero function matlabhistogram matlab exampletaylor series expansionsbinary polynomial divisionmatlab code for bisection methodconvert from ascii to charascii code for alphabetmatrix gauss jordanleast square regression matlabascii values for alphabetshalf life exponential decay formulamultiplying matrices in matlabgauss jordan elimination tutorialmatrix multiplication in matlabmatlab example programsheaviside step function examplesmatlab animationscombinational gatesmatlab input matrixiteration method in matlabwhat is prime factorization of 49sawtooth graphcurve fitting matlab commandcurvefit matlabcramer's rule example11011 binary to decimalnormal random number matlabascii char tablelogarithmic regression calculator onlinerecursion formula calculatorhistogram matlab codehow to use while loop in matlabfourier series in matlab codepolynomial matlabmatlab draw normal distributionrc circuits problemsmatlab matrix inverseanimated matrix movieoctal decimal conversionohms law pie chartplotting 3d vectors in matlabheaviside function integralpie chart matlabevaluate double integral calculatorfinding piecewise functionsscilab programhow to write function in matlabcolor histogram matlab code3 band resistor calculatornumerical integration calculatorcapacitor charging curve11011 binarymatlab solving systems of equationshow do you write a piecewise functionrc circuit simulatormatlab exponential fitbisection method in matlabconversion octal to decimalsimpson matlabplot surface matlabgauss jordan method c programparallel ohm calculator