You are on page 1of 6

PRACTICAL-9

AIM: Writing a brief script with a request input using input to evaluate the function h(t) using if else
statement whare h(t)= t-10 0<t<100 h(t)=0.45*t+900,t>100.

SOFTWARE USED: Matlab 2019.


THEORY:
if expression, statements, end evaluates an expression, and executes a group of statements when the
expression is true. An expression is true when its result is nonempty and contains only nonzero
elements (logical or real numeric). Otherwise, the expression is false. The elseif and else blocks are
optional. The statements execute only if previous expressions in the if...end block are false. An if block
can include multiple elseif blocks.

SYNTAX:
if expression
statements
elseif expression
statements
else
statements
end

CODE:
t= input('Enter the value of t')

if (t>0&t<100)

h=t-10

fprintf('The value of h %d,for the value of t %d is:',h,t)

elseif (t>100)

h=0.45*t+900

fprintf('The value of h %d,for the value of t %d',h,t)

elseif (t==0)

fprintf('Value of t cannot be zero')

elseif (t<0)

fprintf('value of t cannot be neagtive')

end
OUTPUT:

Enter the value of t


25

t =

25
h =

15

The value of h 15,for the value of t 25


PRACTICAL-10
AIM: Basic 2d and 3d plots "parametric space curve, 3d contour lines,2d and 3d pie charts,2d and 3d
bar charts.

SOFTWARE USED: Matlab 2019.


THEORY:
 PARAMETRIC SPACE CURVE
fplot3 (xt,yt,zt) plots the parametric curve xt = x(t), yt = y(t), and zt = z(t) over the default interval –
5 < t < 5. fplot3 (xt,yt,zt,[tmin tmax]) plots xt = x(t), yt = y(t), and zt = z(t) over the
interval tmin < t < tmax. fplot3 (___,LineSpec) uses LineSpec to set the line style, marker symbol, and
line color. fplot3 (___,Name,Value) specifies line properties using one or more Name,Value pair
arguments. Use this option with any of the input argument combinations in the previous syntaxes.

 CONTOUR LINES
contour3(Z) creates a 3-D contour plot containing the isolines of matrix Z, where Z contains height
values on the x-y plane. MATLAB® automatically selects the contour lines to display. The column and
row indices of Z are the x and y coordinates in the plane, respectively. contour3(X,Y,Z) specifies
the x and y coordinates for the values in Z. contour3(___,levels) specifies the contour lines to display
as the last argument in any of the previous syntaxes. Specify levels as a scalar value n to display the
contour lines at n automatically chosen levels (heights).

 PIE CHART

 2D PIE CHART
pie(X) draws a pie chart using the data in X. Each slice of the pie chart represents an element in X.
If sum(X) ≤ 1, then the values in X directly specify the areas of the pie slices. pie draws only a partial
pie if sum(X) < 1. If sum(X) > 1, then pie normalizes the values by X/sum(X) to determine the area of
each slice of the pie. If X is of data type categorical, the slices correspond to categories. The area of
each slice is the number of elements in the category divided by the number of elements in X.

 3D PIE CHART
pie3(X) draws a three-dimensional pie chart using the data in X. Each element in X is represented as a
slice in the pie chart. If sum(X) ≤ 1, then the values in X directly specify the area of the pie
slices. pie3 draws only a partial pie if sum(X) < 1. If the sum of the elements in X is greater than one,
then pie3 normalizes the values by X/sum(X) to determine the area of each slice of the pie.
pie3(X,explode) specifies whether to offset a slice from the center of the pie chart. X(i,j) is offset from
the center of the pie chart if explode(i,j) is nonzero. explode must be the same size as X.

 BAR CHART

 2D BAR CHART
bar(x,y) draws the bars at the locations specified by x. bar(___,width) sets the relative bar width,
which controls the separation of bars within a group. Specify width as a scalar value. Use this option
with any of the input argument combinations in the previous syntaxes. bar(___,style) specifies the
style of the bar groups. For example, use 'stacked' to display each group as one multicolored bar.
bar(___,color) sets the color for all the bars. For example, use 'r' for red bars.

 3D BAR CHART
bar3 draws a three-dimensional bar graph. bar3(Z) draws a three-dimensional bar chart, where each
element in Z corresponds to one bar. When Z is a vector, the y-axis scale ranges from 1 to length(Z).
When Z is a matrix, the y-axis scale ranges from 1 to the number of rows in Z. bar3(Y,Z) draws a bar
chart of the elements in Z at the locations specified in Y, where Y is a vector defining the y values for
the vertical bars. The y values can be nonmonotonic, but cannot contain duplicate values. If Z is a
matrix, elements from the same row in Z appear at the same location along the y-axis.

CODE:
A = pi:0.10:2*pi

x = sin(A)

y = tan(A)

X = [1 3 0.5 2.5 2];

figure,plot(A,x)

title('Simple 2D Plot')

legend('2D Plot')

xlabel('A')

ylabel('sin(A)')

grid on

figure,plot3(A,x,y)

title('3D Plot or Prametric Space curve')

legend('3D Plot')

xlabel('A')

ylabel('sin(A)')

grid on

[A,x,y] = sphere(50);

contour3(A,x,y);

title('Contour 3D Plot')

legend('3D Plot')

grid on

pie(X)

title('Pie 2D Plot')
legend('Pie 2D Plot')

pie3(X)

title('Pie 3D Plot')

legend('Pie 3D Plot')

bar(X)

title('Bar 2D Plot')

legend('2D Plot')

grid on

bar3(X)

title('Bar 3D Plot')

legend('3D Plot')

grid on

OUTPUT:

You might also like