[go: up one dir, main page]

0% found this document useful (0 votes)
91 views6 pages

3 Lab

This document discusses vectors and matrices in MATLAB. It begins by defining scalars, vectors, and matrices, noting that matrices with one row or column are called row and column vectors respectively. It states that MATLAB allows working with complete matrices simultaneously rather than one number at a time. This simplifies problems and makes solutions easier to handle. All variables in MATLAB are treated as single element matrices. The document then defines arrays as lists of numbers arranged in rows and/or columns, noting that a one-dimensional array is a row or column of numbers while a two-dimensional array has numbers arranged in rows and columns. It concludes by stating that array operations are performed element by element.

Uploaded by

khawar
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)
91 views6 pages

3 Lab

This document discusses vectors and matrices in MATLAB. It begins by defining scalars, vectors, and matrices, noting that matrices with one row or column are called row and column vectors respectively. It states that MATLAB allows working with complete matrices simultaneously rather than one number at a time. This simplifies problems and makes solutions easier to handle. All variables in MATLAB are treated as single element matrices. The document then defines arrays as lists of numbers arranged in rows and/or columns, noting that a one-dimensional array is a row or column of numbers while a two-dimensional array has numbers arranged in rows and columns. It concludes by stating that array operations are performed element by element.

Uploaded by

khawar
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/ 6

2.

12 ILLUSTRATIVE PROGRAMS
2.12.1 Task#1
Write a program to calculate area of circle having radius 3cm?

𝐀𝐫𝐞𝐚 𝐎𝐟 𝐂𝐢𝐫𝐜𝐥𝐞 = 𝛑𝐫𝟐

Program
r = 3;
Area = pi * (r ^ 2)
Output
Area =
28.
26

2.12.2 Task#2
Given two sides a=3.2 & b=4.6 of a triangle and angle 60 o between these
two sides, find the length of the third side and the area of the triangle?

𝑪
𝟏
𝑨𝒓𝒆𝒂 𝑶𝒇 𝑻𝒓𝒊𝒂𝒏𝒈𝒍𝒆 = 𝒂𝒃
𝐬𝐢𝐧(𝜽) 𝟐
Program
a=3.2;
b=6.4;
theta=60;
% Length of third side
c= sqrt(a^(2)+b^(2)-2*a*b*cos(theta))
% Area of circle in radians
Area= 0.5*a*b*sind(theta)
% Area of circle in degree
Area= 0.5*a*b*sin(theta)
Output
c =
9.4979

Area =
8.8681

Area =
-3.1213

2.12.3 Task#3
Write a program to convert temperature given in °C say 35.4°C to °F?

°F= 9/5°C+32

Program
C = 35.4;
F=(9/5*C+32)

Output
F =
95.7200

2.12.4 Task4#
Write MATLAB statement and calculate sum of series for x=1.5?

𝒙𝟐 𝒙𝟒 𝒙𝟔 𝒙𝟖
𝒔=𝟏− + − +
𝟐! 𝟒! 𝟔! 𝟖!
Program
x=1.5; s= 1-(x^2/factorial(2))+(x^4/factorial(4))-(x^6/factorial(6))+
(x^8/factorial(8)) Output

s=
0.0708

2.12.5 Task#5
Evaluate the following assignment statements.

1- 𝒒 = 𝟐 𝐥𝐨𝐠𝟏𝟎 𝒙 + 𝐜𝐨𝐬 𝝅 + |𝒚𝟐 − 𝒛𝟐| + √𝟓𝒚𝒛 𝒇𝒐𝒓 𝒙 = 𝟐 , 𝒚 = 𝟒 & 𝒛 = 𝟑

2- 𝐥𝐧(𝒙𝟐 + 𝒙 + 𝟏) 𝒘𝒉𝒆𝒓𝒆 𝒙 = 𝟏 𝒂𝒏𝒅 𝒙 = 𝟏

3- ( 𝒙𝟐+𝟏𝒙)(𝐬𝐢𝐧 𝒙) 𝒘𝒉𝒆𝒓𝒆 𝒙 = 𝝅 𝟒 𝒂𝒏𝒅 𝒙 = 𝝅𝟐


Program
%% q= 2log10x+cos(pi)+|y^2-z^2|+(5yz)^1/2 for x=2, y=4 &
z=3 x=2; y=4; z=3; q= 2*log10(x)+cos(pi)+abs(y^2-
z^2)+sqrt(5*y*z)

%% ln(x^2+x+1) where x=1/2 and x=1


x=1/2; r=
log(x^2+x+1
) x=1; s=
log(x^2+x+1
)

%% x/(x^2+1)(sinx)
x=pi/4;
t=
(x./(x.^2+1).*sin(x)
) x=pi/2; u=
(x./(x.^2+1).*sin(x)
) Output

q =
14.3480
r =
0.5596 s
=
1.0986
t =
0.3435
u =
0.4530

2.12.6 Task#6
Evaluate the given number for ‘x’ from 1 to 2 in steps of 0.1.

𝟏 𝒙𝟑
𝒚 = 𝒙 + 𝒙𝟒 + 𝟓𝒙 𝐬𝐢𝐧 𝒙

Program
x=1:0.1:2;
y= (1./x)+((x.^3))./((x.^4)+(5.*x.*sin(x)))
Output
Columns 1 through 6
1.1920 1.1182 1.0587 1.0102 0.9698 0.9357

Columns 7 through 11

0.9065 0.8810 0.8583 0.8378 0.8188

2.12.7 Task#7
Write assignment statements to evaluate the following equations:

(A) 𝑽𝒐𝒍𝒖𝒎𝒆 = 𝝅𝒓𝟐𝒉 𝒇𝒐𝒓 𝒓 = 𝟐, 𝒉 = 𝟑

(B) 𝑷𝒐𝒘𝒆𝒓 = 𝟐𝝅𝑵𝑻 𝒇𝒐𝒓 𝑵 = 𝟏𝟎𝟎𝟎 , 𝑻 = 𝟏𝟎


𝟔𝟎

𝑽𝑰 𝐜𝐨𝐬 𝜽
(C) 𝑬𝒇𝒇𝒊𝒄𝒊𝒆𝒏𝒄𝒚 = 𝑽𝑰 𝐜𝐨𝐬 𝜽 +𝑰𝟐 𝑹+𝝎𝒄 𝒇𝒐𝒓 𝑽 =
𝟐𝟓𝟎 , 𝑰 = 𝟓 , 𝑹 = 𝟐 , 𝐜𝐨𝐬 𝜽 = 𝟎. 𝟖 , 𝝎𝒄 = 𝟐𝟎

Program
%% Volume =
pi*r^2*h r=2;
h=3; v=
pi*(r^2)*h

%% Power= 2piNT/60
N= 1000; T=
10; p=
(2*pi*N*T)/6
0
%% Efficiency= VIcos(theta)/VIcos(theta)+I^2R+Wc
V=250;
I=5;
R=2;
theta=
0.8;
Wc=20;
e= V*I*cos(theta)/V*I*cos(theta)+I^2*R+wrightOmega(Wc)
Output
v =
37.699
1 p =

1.0472e+0
3 e =

79.2926

2.12.8 Task#8
For an electrical circuit with an inductance l=0.01mh and resistance r=180 ohms the
damped natural frequency of oscillations is:

𝟏 𝑹 𝟐
𝑭𝒓𝒆𝒒𝒖𝒆𝒏𝒄𝒚 √ 𝑳𝑪 − 𝟒𝑪𝟐
=

Write a program to calculate the frequency for different values of ‘c’ varying from 0.1 to 1
in step of 0.1.

Program
L=0.01;
R=180;
C=0.1:0.1:1;
F=sqrt((1./L.*C)+(R.^2)/4.*(C.^2))
Output
F =
Columns 1 through 9
9.5394 18.5472 27.5500 36.5513 45.5522 54.5527 63.5531
72.5534
81.5537

Column 10
90.5539

3 LAB#3
IMPLEMENTATION OF VECTORS
The learning objectives are:

• Knowledge of scalar, vectors and matrices and basic operations such as product and
transpose
• Useful commands/functions related to vectors and matrices
3.1 Introduction
The matrix notation usually simplifies the complex mathematical expressions /equations and
makes solution of problems much easier to handle and manipulate. In MATLAB, a matrix is a
rectangular array of real or complex numbers. Matrices with only one row or with only one
column are called row and column vectors, respectively. A matrix having only one element is
called a scalar.

Although other higher programming languages work with one number at a time, in MATLAB it
is possible to work with complete matrix simultaneously. This feature is very important as it
removes the un-necessary loops and repetition of same statements. The program, therefore,
becomes short, concise and easily understandable. In MATLAB, matrix is chosen as a basic data
element. All variables when used as a single data element are treated as single element matrix
that is a matrix with one row and one column.

3.2 Arrays
An array is a list of numbers arranged in rows and/or columns. A one-dimensional array is a row
or a column of numbers and a two dimensional array has a set of numbers arranged in rows and
columns. An array operation is performed element by element.

You might also like