Lab 2
Lab 2
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No: 2 Roll No:CH-20007
Lab 2: To learn about the plotting of graphs on MATLAB and use different
Title:
Task 1: Plot a two-dimensional graph using “plot ()” and “subplot ()” function with title and
axeslabeling and plot aesthetics.
Task 2: For given equation, make equation with strings, draw it with ezplot () or fplot ().
Question: Draw the equation y = 2x^3 + x^2 + 4x + 5, for x interval [-3 3] with ezplot () and
plot().
Task 3: Make surface plot by using SURF and CONTOUR plots functions
Description:
1. ln task 1, we have learnt to plots graphs using plot () and subplot () and learnt
various colorscoding etc.
2. In task 2, we plotted the roots of equations using ezplot.
3. In task 3, we plotted surface plot using SURF and CONTOUR plots functions.
TASK 1:
Programs:
mfiles
1. mfile: lab2ex1
x=-6*pi:0.01:6*pi; y=sin(x);
plot (x, y);
title ('y=sin(x)');
xlabel ('x-Axis');
ylabel ('y-Axis');
2. mfile: lab2ex2
x=-6*pi:0.01:6*pi;
y=sin(x);
plot (x,y,'gx');
% gx means to change the color of the plot to green and bold it
%Put 'rx' to change it to red and 'bx' to blue.
title ('y=sin(x)');
xlabel ('x-Axis');
ylabel ('y-Axis');
1
Date:7/10/23
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No: 2 Roll No:CH-20007
3. mfile: lab2ex3
x=-8:0.01:8;
y=x.^2; z=3.*x;
plot (x,y,x,z);
xlabel ('x-Axis');
ylabel ('y-Axis');
gtext ('y=x^2');
gtext ('z=3x');
4. mfile: lab2ex4
x=linspace(0,50,100);
y=x.^2;
z=3.*x; t=5.*x;
u=(x.^3)-x;
subplot (2,2,1);
plot (x,y);
xlabel ('x-Axis');
ylabel ('y-Axis');
subplot (2,2,2);
plot (x,z);
2
Date:7/10/23
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No: 2 Roll No:CH-20007
xlabel ('x-Axis');
ylabel ('z-Axis');
subplot (2,2,3);
plot (x,t);
xlabel ('x-Axis');
ylabel ('t-Axis');
subplot (2,2,4);
xlabel ('x-Axis');
ylabel ('u-Axis');
1. mfile: lab2ex1
3
Date:7/10/23
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No: 2 Roll No:CH-20007
2. mfile: lab2ex2
4
Date:7/10/23
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No: 2 Roll No:CH-20007
3. mfile: lab2ex3
5
Date:7/10/23
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No: 2 Roll No:CH-20007
4. mfile: lab2ex4
Result:
Two dimensional graphs of the above programs by using plot() and subplot() function has been observed.
Task 2: For given equation, make equation with strings, draw it with ezplot() or fplot().
Question: Draw the equation y = 2x^3 + x^2 + 4x + 5, for x interval [-3 3] with ezplot() and
plot(). mfile:
lab2ex5
clear all close all; clc;
ys='2*x^3+ x^2 + 4* x +5';
ezplot(ys,[-3,3]); grid on ; hold on
x = -3:0.1:3;
y = 2*x.^3+ x.^2 + 4* x +5;
plot(x,y,'r.')
6
Date:7/10/23
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No: 2 Roll No:CH-20007
COMMAND WINDOW:
RESULTS:
5. mfile: lab2ex5
Result
The equation y = 2x3 + x2 + 4x +5, for x intervals [-3,3] with ezplot () and plot().
Task 3: Make surface plot by using SURF and CONTOUR plots functions
mfiles
Program 3:
X=-2:.1:2;
Y=-2:.1:2;
[X,Y]=meshgrid(X,Y); Z=-X.^2+Y.^2;
surf (X,Y,Z);
7
Date:7/10/23
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No: 2 Roll No:CH-20007
Program 2:
X=1:0.5:10;
Y=1:0.5:20;
[X,Y] = meshgrid(X,Y); Z = sin(X) + cos(Y);
surf(X,Y,Z);
Program 3:
x = linspace(-2*pi,2*pi); y = linspace(0,4*pi);
[X,Y] = meshgrid(x,y); Z = sin(X)+cos(Y);
contour(X,Y,Z)
Program 4
[X,Y,Z] = peaks;
contour(X,Y,Z,20)
Program 5
[X,Y,Z] = peaks;
contour(X,Y,Z,'--')
8
Date:7/11/
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-
Lab No: 2 Roll No:CH-
Command window:
Program 1
9
Date:7/11/
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-
Lab No: 2 Roll No:CH-
Program:2
Program:3
1
Date:7/11/
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-
Lab No: 2 Roll No:CH-
Program:4
Program:5
1
Date:7/11/
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-
Lab No: 2 Roll No:CH-
Program:6
Program:7
1
Date:7/11/
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-
Lab No: 2 Roll No:CH-
Program:8
RESULT:
Surface plot of the above programs by using SURF and CONTOUR plots has been observed.