Experiment No 03
Experiment No 03
Apparatus:
1. MATLAB Software.
MATLAB Code:
>> x = [1 2 3 4 5];
>> y = x.^2;
>> plot(x,y)
>> x = -10:0.2:10;
>> y1 = x.^2;
>> y2 = x.^3;
>> plot(x,y1,x,y2)
>> x = -10:1:10;
>> y1 = x.^2;
>> y2 = x.^3;
>> plot(x,y1,'r*-',x,y2,'b+:')
>> plot(x,y1,'r*-',x,y2,'b+:')
>> title('y1=x^2 and y2=x^3')
>> xlabel('x axis')
>> ylabel('y axis')
>> grid on
>> legend('x^2','x^3')
% Trigonometric Function
>> x = 0:0.01:2*pi;
>> y = sin(x);
>> plot(x, y)
>> title('y = sin(x)')
>> xlabel('x')
>> ylabel('sin(x)')
>> grid on
% 3D Surface Plot
>> x = -2*pi:0.1:2*pi;
>> y = -2*pi:0.1:2*pi;
>> [X, Y] = meshgrid(x, y);
>> Z = sin(X) .* cos(Y);
>> surf(X, Y, Z)
>> xlabel('X-axis')
>> ylabel('Y-axis')
>> zlabel('Z-axis')
>> title('3D Surface Plot of z = sin(x) * cos(y)')
>> grid on
Conclusion: Plotting mathematical functions in MATLAB provides an effective and visual
way to understand and analyse the behaviour of functions. With a variety of built-in tools for
creating both 2D and 3D plots, MATLAB enables users to graph a wide range of mathematical
expressions, from simple equations to complex surfaces. These visualizations help in
interpreting patterns, relationships and trends within data or functions, making MATLAB an
essential tool for students, engineers and researchers. Overall, MATLAB's plotting capabilities
enhance both mathematical insight and the clarity of data presentation.