0% found this document useful (0 votes)
21 views

MATLAB Commands

Uploaded by

annexshaw26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

MATLAB Commands

Uploaded by

annexshaw26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

>> clear
>> (1+sqrt(5))/2

ans =

1.618033988749895

>> GoldenRatio = ans

GoldenRatio =

1.618033988749895

2.
>> x = [0 pi/2 pi/4 pi/6 pi 2*pi]

x =

0 1.570796326794897 0.785398163397448
0.523598775598299 3.141592653589793 6.283185307179586

>> a = cos(x)

a =

1.000000000000000 0.000000000000000 0.707106781186548


0.866025403784439 -1.000000000000000 1.000000000000000

>> b = sin (x)

b =

0 1.000000000000000 0.707106781186547
0.500000000000000 0.000000000000000 -0.000000000000000

>> c =tan (x)

c =

1.0e+16 *

0 1.633123935319537 0.000000000000000
0.000000000000000 -0.000000000000000 -0.000000000000000

3.
>> r = [1 2 3 4]
r =

1 2 3 4

>> Area = pi*[r.^2]

Area =

3.141592653589793 12.566370614359172 28.274333882308138


50.265482457436690

4.
>> a = [0:2:10]

a =

0 2 4 6 8 10

>> b = linspace (0,10,5)

b =

0 2.500000000000000 5.000000000000000
7.500000000000000 10.000000000000000

>> b = linspace (0,10,6)

b =

0 2 4 6 8 10

>> c=a+b

c =

0 4 8 12 16 20

>> size (c)

ans =

1 6

5.
>> clear
>> X= [0 : 0.3 : 2*pi]
X =

Columns 1 through 6

0 0.300000000000000 0.600000000000000
0.900000000000000 1.200000000000000 1.500000000000000

Columns 7 through 12

1.800000000000000 2.100000000000000 2.400000000000000


2.700000000000000 3.000000000000000 3.300000000000000

Columns 13 through 18

3.600000000000000 3.900000000000000 4.200000000000000


4.500000000000000 4.800000000000000 5.100000000000000

Columns 19 through 21

5.400000000000000 5.700000000000000 6.000000000000000

>> Ya = cos(X)

Ya =

Columns 1 through 6

1.000000000000000 0.955336489125606 0.825335614909678


0.621609968270665 0.362357754476674 0.070737201667703

Columns 7 through 12

-0.227202094693087 -0.504846104599858 -0.737393715541245 -


0.904072142017061 -0.989992496600445 -0.987479769908865

Columns 13 through 18

-0.896758416334147 -0.725932304200140 -0.490260821340699 -


0.210795799430780 0.087498983439446 0.377977742712980

Columns 19 through 21

0.634692875942635 0.834712784839160 0.960170286650366

>> Yb = sin(X)

Yb =

Columns 1 through 6
0 0.295520206661340 0.564642473395035
0.783326909627483 0.932039085967226 0.997494986604054

Columns 7 through 12

0.973847630878195 0.863209366648874 0.675463180551151


0.427379880233830 0.141120008059867 -0.157745694143249

Columns 13 through 18

-0.442520443294852 -0.687766159183974 -0.871575772413588 -


0.977530117665097 -0.996164608835841 -0.925814682327732

Columns 19 through 21

-0.772764487555987 -0.550685542597638 -0.279415498198926

>> plot(X,Ya,X,Yb)

6.
>> A = [1,2,3,4;11,12,13,14;21,22,23,24]

A =

1 2 3 4
11 12 13 14
21 22 23 24

>> size(A)

ans =

3 4
>> B= A(3, :)
B =

21 22 23 24

>> D = A(:,2)

D =

2
12
22

>> A=A'

A =

1 11 21
2 12 22
3 13 23
4 14 24

You might also like