You are on page 1of 12

1.

Constructing Program in MATLAB


1.1. MATLAB as a Calculator:
1.1.1. Symbol “^”
This symbol takes the power of any quantity as it can be observed from MATLAB
code shown in Figure 1.

Figure 1: MATLAB Result 1.1.1

1.1.2. ^0.5
This expression takes the square root of any digit or quantity when written after that
and it can be observed from Figure 2.

Figure 2: MATLAB Result 1.1.2


𝟔
1.1.3. 𝟓 −
𝟑(𝟗−𝟕)
Output and input commands for this expression can be observed from Figure 3.

Figure 3: MATLAB Result 1.1.3


𝟓𝟐
𝟕𝟗−( 𝟒 −𝟕)
1.1.4. 𝟐𝟑
+𝟏𝟏
𝟕

Figure 4: MATLAB Result 1.1.4


𝟑∗(𝟏𝟎𝟎−𝟕𝟐)
𝟓(𝟏𝟔−𝟑)
1.1.5. 𝟐[𝟐𝟓− 𝟒
]

𝟑

Figure 5: MATLAB Result 1.1.5


𝟕
𝟐 𝟑
1.1.6. 𝟏𝟔 + 𝟒
𝟕 𝟓

Figure 6: MATLAB Result 1.1.6


1.1.7. 2+3/4*5

𝟑
The answer of this expression in MATLAB is left one, which is 𝟐 + ∗ 𝟓
𝟒

Figure 7: MATLAB Result 1.1.7

1.1.8. (2+3)^4/5

(𝟐+𝟑)𝟒
The answer of this expression in MATLAB is right one, which is
𝟓

Figure 8: MATLAB Result 1.1.8

1.1.9. 2/3/4/5

𝟐
𝟑
𝟒
The answer of this expression in MATLAB is right one, which is
𝟓

Figure 9: MATLAB Result 1.1.9


1.1.10. 2^3^4

The answer of this expression in MATLAB is left one, which is (23 )4

Figure 10: MATLAB Result 1.1.10

1.2. Using Variables:


1.2.1. Simple Resistive Circuit:

Figure 11: MATLAB Result 1.2.1

Therefore, resistance is 20Kω.


1.2.2. PI

Figure 12: MATLAB Result 1.2.2


1.2.3. i & j

i and j both are imaginary numbers and can be observed in MATLAB with zero in
real part.

Figure 13: MATLAB Result 1.2.3.

1.2.4. Z = pi +4i

Figure 14: MATLAB Result 1.2.4

1.2.5. pi=7 and i=5, then z=pi+4*i

When this type of assignment is done then the MATLAB defined


values of pi and i changes to user defined value and result will be
updated with new values.

Figure 15: MATLAB


Result 1.2.5.
1.3. Functions:
1.3.1. Sin(0)

Figure 16: MATLAB Result 1.3.1

1.3.2. Sin(π)

Figure 17: MATLAB Result 1.3.2

1.3.3. Tan(π/2)

Figure 18: MATLAB Result 1.3.3

Yes, this is a strange behavior from MATLAB because this value should be infinity
but for MATLAB this value of 1016 is very large value almost equal to infinity.
1.3.4. Cos-1(-1)

Figure 19: MATLAB Result 1.3.4

1.3.5. e-1

Figure 20: MATLAB Result 1.3.5

1.3.6. ln(e2)

Figure 21: MATLAB Result 1.3.6

1.3.7. log10(100)

Figure 22:MATLAB Result 1.3.7


1.3.8. √9.8696

Figure 23: MATLAB Result 1.3.8

1.4. Arrays:
1.4.1. Multiplication of Array by 2

Figure 24: MATLAB Result 1.4.1

1.4.2. Odd Array

Figure 25: MATLAB Result 1.4.2


1.4.3. Even Array

Figure 26: MATLAB Results 1.4.3

1.4.4. Addition of Arrays:

Figure 27: MATLAB Result 1.4.4

1.4.5. Multiplication of Arrays:

Figure 28: MATLAB Result 1.4.5

Multiplication between two arrays called even and odd does not happen in our case
because this is like matrix multiplication and for this to happen matrix dimensions
should be satisfied. This case does not follow matrix multiplication rule so
MATLAB gives dimension error.
1.4.6. Multiplication by “.*” Operator

Figure 29: MATLAB Result 1.4.6

This operator multiplies each element of an array with other element of second
array positioned at the same location.
1.4.7. Concatenating Arrays:

Figure 30: MATLAB Result 1.4.7

This command merges two arrays meaning at the end of 1st placed array there will
be 2nd array in the concatenated array.
1.5. Plotting:
1.5.1. Array with Steps:

Figure 31:MATLAB Results 1.5.1

1.5.2. Observing the above Array:

After observing the above array it can be declared that the last value of array “x” is
not 2π. The reason behind this scenario is only those numbers are selected as element
of array “x” which have a difference of 0.1 between adjacent numbers. Therefore
2π= 6.28 cannot be selected.
1.5.3. Creating two Arrays of Different Sizes:

Figure 32: MATLAB Result 1.5.3


1.5.4. Plotting y=sin(x)

Figure 33: MATLAB Result 1.5.4

You might also like