Showing posts with label basic operations on vectors. Show all posts
Showing posts with label basic operations on vectors. Show all posts

Assignment Operator in C++

The declaration of class CMyString is found in Listing 2-9. Please add an assignment operator to it.

Listing 2-9. C++ Code for Declaration of CMyString 
 class CMyString {
 
public:
    CMyString(char* pData = NULL);
    CMyString(const CMyString& str);
    ~CMyString(void);
private:
    char* m_pData;
};
www.cinterviews.com appreciates your contribution please mail us the questions you have to cinterviews.blogspot.com@gmail.com so that it will be useful to our job search community

What are basic operations on vectors-Matlab tutorials

following from previous post --acessing elements in vector
What are Basic operations on vectors

Once you master the notation you are free to perform other operations:
>> v(1:3)-v(2:4)
ans =
-2 -2 -2

For the most part Matlab follows the standard notation used in linear algebra. We will see later that there are some extensions to make some operations easier. For now, though, both addition subtraction are defined in the standard way. For example, to define a new vector with the numbers from 0 to -4 in steps of -1 we do the following:

>> u = [0:-1:4]
u = [0:-1:-4]
u =
0 -1 -2 -3 -4

We can now add u and v together in the standard way:
>> u+v
ans =
0 1 2 3 4

Additionally, scalar multiplication is defined in the standard way. Also note that scalar division is defined in a way that is consistent with scalar multiplication:

>> -2*u
ans =
0 2 4 6 8
>> v/3
ans =
0 0.6667 1.3333 2.0000 2.6667

With these definitions linear combinations of vectors can be easily defined and the basic operations combined:
>> -2*u+v/3
ans =
0 2.6667 5.3333 8.0000 10.6667

You will need to be careful. These operations can only be carried out when the dimensions of the vectors allow it. You will likely get used to seeing the following error message which follows from adding two vectors whose dimensions are different:
>> u+v'
??? Error using ==> plus
Matrix dimensions must agree.