Professional Documents
Culture Documents
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.
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
elseif (t>100)
h=0.45*t+900
elseif (t==0)
elseif (t<0)
end
OUTPUT:
t =
25
h =
15
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)
figure,plot(A,x)
title('Simple 2D Plot')
legend('2D Plot')
xlabel('A')
ylabel('sin(A)')
grid on
figure,plot3(A,x,y)
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: