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

Matlab Assignmnent 1

The document contains solutions to various math and programming questions. It includes solutions involving formatting numbers, arithmetic operations, functions like fix(), floor(), sqrt(), trigonometric functions, random number generation, arrays, matrices, and the clock function.

Uploaded by

Umaima
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Matlab Assignmnent 1

The document contains solutions to various math and programming questions. It includes solutions involving formatting numbers, arithmetic operations, functions like fix(), floor(), sqrt(), trigonometric functions, random number generation, arrays, matrices, and the clock function.

Uploaded by

Umaima
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 23

SOLUTION OF Q3:-

format +

>> 12.34

ans =

>> -123

ans =

>> format bank

>> 33.4

ans =

33.40

>> 52.435

ans =
52.44

SOLUTION OF Q4:-
>> 5/16 + 2/7

ans =

0.60

>> format rat

>> 5/16 + 2/7

ans =

67/112

SOLUTION OF Q6:-
>> pounds = 30;

>> kilos = pounds / 2.2

kilos =

13.6364

SOLUTION OF Q7:-
>> r1= 3;

>> r2= 4.5;

>> r3= 2.2;

>> rt= 1/(1/r1 + 1/r2 + 1/r3)

rt =

0.9900

SOLUTION OF Q9:-
>> sind (90)

ans =

SOLUTION OF Q11:-
>> t= 20;

>> v= 11;

>> WCF=35.7 + 0.6*t - 35.7*v^0.16+ 0.43*t*v^0.16

WCF =

7.9267

SOLUTION OF Q12:-
>> fix(3.5)

ans =

>> floor(3.5)

ans =

>> fix(3.4)

ans =

>> floor(-3.4)

ans =

-4
>> fix(3.4)

ans =

>> fix(-3.4)

ans =

-3

>> fix(3.2)

ans =

>> floor(3.2)

ans =

>> fix(-3.2)
ans =

-3

>> floor(-3.2)

ans =

-4

>> fix(-3.2)

ans =

-3

>> ceil(-3.2)

ans =

-3

SOLUTION OF Q13:-
>> sqrt(19)
ans =

4.3589

>> 3^1.2

ans =

3.7372

>> tan(pi)

ans =

-1.2246e-016

SOLUTION OF Q17:-
>> rand

ans =

0.9501

>> rand*20
ans =

4.6228

>> low= 20;

>> high= 50;

>> rand* (high - low)+low

ans =

38.2053

>> round (rand*10)

ans =

>> round(rand *11)

ans =

10
>> round (rand*(100 - 50)+ 50)

ans =

88

SOLUTION OF Q21:-
>> 3:6

ans =

3 4 5 6

>> 1:.5:3

ans =

1.0000 1.5000 2.0000 2.5000 3.0000

>> 5:-1:2

ans =

5 4 3 2
SOLUTION OF Q22:-
>> linspace(4,8,3)

ans =

4 6 8

>> linspace(-3,-15,5)

ans =

-3 -6 -9 -12 -15

>> linspace(9,5,3)

ans =

9 7 5

SOLUTION OF Q23:-
>> 1:10

ans =
1 2 3 4 5 6 7 8 9 10

>> linspace(1,10,10)

ans =

1 2 3 4 5 6 7 8 9 10

>> 2:5:12

ans =

2 7 12

>> linspace(2,12,3)

ans =

2 7 12

SOLUTION OF Q24:-
>> myend= randint(1,1,[8,12])

myend =
10

myend(:,:,1) =

0.3340

myend(:,:,2) =

0.4329

myend(:,:,3) =

0.2259

myend(:,:,4) =

0.5798

myend(:,:,5) =

0.7604
myend(:,:,6) =

0.5298

myend(:,:,7) =

0.6405

myend(:,:,8) =

0.2091

>> myend= rand*(12-5)+5

myend =

7.6587

>> vec= 1:3:myend

vec =
1 4 7

SOLUTION OF Q26:-
>> vec= 1:8;

>> vec(1:2:end)

ans =

1 3 5 7

>> vec= 1:10;

>> vec(1:1:end)

ans =

1 2 3 4 5 6 7 8 9 10

SOLUTION OF Q28:-
>> mat=[7:-1:5 ; 3:2:7]

mat =

7 6 5

3 5 7
SOLUTION OF Q29:-
>> rand (2,3)

ans =

0.7833 0.4611 0.7942

0.6808 0.5678 0.0592

>> rand(2,3)*10

ans =

6.0287 4.1537 8.7437

0.5027 3.0500 0.1501

>> randint(2,3,[5,20])

ans =

17 20 12

20 17 12

>> rand(2,3,[5,20])
ans(:,:,1) =

0.2140 0.3200 0.7266

0.6435 0.9601 0.4120

ans(:,:,2) =

0.7446 0.4399 0.6833

0.2679 0.9334 0.2126

ans(:,:,3) =

0.8392 0.1338 0.6072

0.6288 0.2071 0.6299

ans(:,:,4) =

0.3705 0.4514 0.0272

0.5751 0.0439 0.3127


ans(:,:,5) =

0.0129 0.6831 0.0353

0.3840 0.0928 0.6124

>> randint(2,3,[5,20])

ans =

14 5 14

5 8 5

SOLUTION OF Q31:-
>> mat=[7:10; 12:-2:6]

mat =

7 8 9 10

12 10 8 6

>> mat(1,3)

ans =

9
>> mat(2,:)

ans =

12 10 8 6

>> mat(:,1:2)

ans =

7 8

12 10

SOLUTION OF Q32:-
>> mymat= [2 5 8; 7 5 3]

mymat =

2 5 8

7 5 3

>> (mymat)'

ans =
2 7

5 5

8 3

>> reshape(mymat,3,2)

ans =

2 5

7 8

5 3

>> fliplr(mymat)

ans =

8 5 2

3 5 7

>> (fliplr(mymat))'

ans =

8 3
5 5

2 7

>> repmat(mymat,1,2)

ans =

2 5 8 2 5 8

7 5 3 7 5 3

SOLUTION OF Q33:-
>> mymat= zeros(4,2)

mymat =

0 0

0 0

0 0

0 0

>> mymat(2,:)= [3 6]

mymat =

0 0

3 6
0 0

0 0

SOLUTION OF Q34:-
>> x = -pi:pi:20 ;

>> y = sin(x)

y=

1.0e-015 *

-0.1225 0 0.1225 -0.2449 0.3674 -0.4899 0.6123 -0.7348

SOLUTION OF Q37:-
>> mat = rand (3,5)

mat =

0.3676 0.6927 0.4418 0.6756 0.4784

0.6315 0.0841 0.3533 0.6992 0.5548

0.7176 0.4544 0.1536 0.7275 0.1210

>> mat(3,:)= []

mat =
0.3676 0.6927 0.4418 0.6756 0.4784

0.6315 0.0841 0.3533 0.6992 0.5548

SOLUTION OF Q38:-
>> myc= clock

myc =

1.0e+003 *

2.0190 0.0040 0.0230 0 0.0240 0.0195

>> today = myc(1:3)

today =

2019 4 23

>> now = myc (4:end)

now =

0 24.0000 19.5340
>> fix(now)

ans =

0 24 19

You might also like