You are on page 1of 11

>> s=[5 3 1 -1 -3 -5]

s=

5 3 1 -1 -3 -5

>> s(2 : 5)

ans =

3 1 -1 -3

>> s(1 : 2 : 5)

ans =

5 1 -3

>> s (6 : -2 : 2)

ans =
-5 -1 3

>> a=[5 3 1 -1 -3 -5]

a=

5 3 1 -1 -3 -5

>> a=s(2 : 5)

a=

3 1 -1 -3

>> b=s(1 : 2 : 5)

b=

5 1 -3

>> c=s (6 : -2 : 2)
c=

-5 -1 3

>> d=[a b]

d=

3 1 -1 -3 5 1 -3

>> e=[b c]

e=

5 1 -3 -5 -1 3

>> d=[a;b]

??? Error using ==> vertcat

CAT arguments dimensions are not consistent.

>> e=[b;c]
e=

5 1 -3

-5 -1 3

>> x=(-3 -2 -1 0 1 2 3 4 5)

??? x=(-3 -2 -1 0 1 2 3 4 5)

Error: Unexpected MATLAB expression.

>> x=(-3 : 1 : 5)

x=

-3 -2 -1 0 1 2 3 4 5

>> x=(-3 : 5)

x=

-3 -2 -1 0 1 2 3 4 5
>> y=x^3+2*x^2-3*x-4

??? Error using ==> mpower

Inputs must be a scalar and a square matrix.

To compute elementwise POWER, use POWER (.^) instead.

>> y=x.^3+2*x.^2-3*x-4

y=

-4 2 0 -4 -4 6 32 80 156

>> k=2

k=

>> m=[2 -6 4 8 -12 1]

m=

2 -6 4 8 -12 1
>> m*k

ans =

4 -12 8 16 -24 2

>> m.^k

ans =

4 36 16 64 144 1

>> m/k

ans =

1.0000 -3.0000 2.0000 4.0000 -6.0000 0.5000

>> linspace (2,8,5)

ans =
2.0000 3.5000 5.0000 6.5000 8.0000

>> linspace(4,-4,5)

ans =

4 2 0 -2 -4

>> [a=linspace (-4,0,5);linspace(4,-4,5);linspace(2,8,5)]

??? [a=linspace (-4,0,5);linspace(4,-4,5);linspace(2,8,5)]

Error: The expression to the left of the equals sign is not a valid target for an assignment.

>> a=[linspace(-4,0,5);linspace(4,-4,5);linspace(2,8,5)]

a=

-4.0000 -3.0000 -2.0000 -1.0000 0

4.0000 2.0000 0 -2.0000 -4.0000

2.0000 3.5000 5.0000 6.5000 8.0000


>> b=[linspace(-1 0 -1 2 -2 ;(2:2:10);linspace(2,-2,5)]

??? b=[linspace(-1 0 -1 2 -2 ;(2:2:10);linspace(2,-2,5)]

Error: Unexpected MATLAB expression.

>> b=[linspace(-1 0 -1 2 -2 ;(2:2:10);linspace(2,-2,5)]

??? b=[linspace(-1 0 -1 2 -2 ;(2:2:10);linspace(2,-2,5)]

Error: Unexpected MATLAB expression.

>> b=[-1 0 -1 2 -2 ;(2:2:10);linspace(2,-2,5)]

b=

-1 0 -1 2 -2

2 4 6 8 10

2 1 0 -1 -2

>> a + b

ans =
-5.0000 -3.0000 -3.0000 1.0000 -2.0000

6.0000 6.0000 6.0000 6.0000 6.0000

4.0000 4.5000 5.0000 5.5000 6.0000

>> 2.*A-B

??? Undefined function or variable 'A'.

>> 2.*a-b

ans =

-7 -6 -3 -4 2

6 0 -6 -12 -18

2 6 10 14 18

>> a.*b

ans =

4.0000 0 2.0000 -2.0000 0

8.0000 8.0000 0 -16.0000 -40.0000

4.0000 3.5000 0 -6.5000 -16.0000


>> b'

ans =

-1 2 2

0 4 1

-1 6 0

2 8 -1

-2 10 -2

>> 2*b'

ans =

-2 4 4

0 8 2

-2 12 0

4 16 -2

-4 20 -4

>>
>>

You might also like