Professional Documents
Culture Documents
Lab 5
Lab 5
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No:05 Roll No:CH-20313
LAB ASSESSMENT RUBRICS
temperatures(℃) 40 48 56 64 72 80
emf(mV) 1.33 1.67 2.08 2.36 2.71 3.19
CODES:
1)m. file:
%prob_2 example of linear interpolation
clear all; close all; clc
x=[40 48 56 64 72 80];
y=[1.33 1.67 2.08 2.36 2.71 3.19];
xx=[40:80]; yy=interp1(x,y, xx);
plot(x,y,'bo-',xx,yy,'g.-'); hold on; xlabel('Temp(degree)');
ylabel('emf(mV)');
x2=[52 77]; y2=interp1(x,y, x2);
plot(x2,y2,'r*')
legend('given points','1st interpolation','1st interpolationgiven points','2');
2) COMMAND WINDOW:
Date: DEC-12-2023
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No:05 Roll No:CH-20313
CODES:
1)m. file:
%prob_3 linear interpolation with two independent v.
clear all; close all;
x=[0 1 2 3 4 5]; % 1x6
y=[2000 3000 4000 5000 6000]; % 1x5
z=[ 0 0 0 0 0
20 110 176 190 240
60 180 220 285 327
68 240 349 380 428
77 310 450 510 620
110 405 503 623 785] % 6x5 matrix.
surf(x,y,z'); % or surf(x',y',z)
xlabel('Time(sec)'); ylabel('Speed(rpm)');
zlabel('Temperature(Degree)');
fprintf('Table 1. Engine Temperature variation for time(sec) vs.rpm.\n')
fprintf('time, rpm :'); fprintf('%6d',y); fprintf('\n');
for i=1:length(x);
fprintf('%3d ',x(i)); fprintf('%6d',z(i,:));
fprintf('\n');
end
x1=input('time=');
while x1 ~= 0;
y1=input('rpm='); z1=interp2(x,y,z',x1,y1);
fprintf('t=%3.1fsec, rpm=%4d RMP,temp= %6.2f(C)\n',x1,y1,z1);
x1=input('time=');
end
2) COMMAND WINDOW:
Date: DEC-12-2023
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No:05 Roll No:CH-20313
CODES:
1)m. file:
%prob_4.m Example of Cubic Spline
clear all; close all; clc;
x = 0: 2*pi/4: 2*pi; y = sin(x); % make 5 points of x; calc y with sin(x);
Date: DEC-12-2023
LAB MANUAL
CHEMICAL PROCESS OPTIMIZATION (CH-404)
Lab No:05 Roll No:CH-20313
plot(x, y,'or'); hold on; % draw given 5 points with plot( ,'o'); hold on;
ezplot('sin(x)',[0 2*pi]);% draw sine curve with ezplot(); %interval 0 to 2pi.
xx = [0: 2*pi/20: 2*pi]; % make 21 points of xx; % increment 2*pi/20
yy = spline(x,y,xx); % calculate yy with spline; % (withoutboth ends slope)
plot(xx, yy,'-c.') % draw calculated values with plot( ,'-c.');
y2=spline(x,[1 y 1],xx); % both ends slope is all 1 at x=0,2pi. dsin(x)/dx = cos(x)
plot(xx,y2,'-m.') ; % draw y2 with plot( ,'-r.');
legend('given point','original sine curve','without slope','with slope','1')
red points and line are spline values with both ends slope. (itis nearly same to true
curve ?!)
2) COMMAND WINDOW: