0% found this document useful (0 votes)
6 views5 pages

KP 09 Nov

The document discusses solving an optimization problem using Matlab. It presents the cost function, initial values, gradient and Hessian computations, and performs iterations using Newton's method to find the minimum. It also shows fitting a curve to pressure-temperature data and calculating drug release over time.

Uploaded by

hr.rayhman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

KP 09 Nov

The document discusses solving an optimization problem using Matlab. It presents the cost function, initial values, gradient and Hessian computations, and performs iterations using Newton's method to find the minimum. It also shows fitting a curve to pressure-temperature data and calculating drug release over time.

Uploaded by

hr.rayhman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Matlab Task

Q1. Matlab Script:


clc
close all
clear all

% Newton's Method
clc
clear
format long
% Given parametres
a = 0.20; c_c = 12.50; c_i = 0.50 ;c_x = 0.90; I = 0.10 ;
n = 2; p = 7000 ;
% Defining function
syms X Y;
% COST FUNCTION f , Variables t =X and q=Y
f = c_c+c_i+c_x+(2.09*10^4 /360)*X^(-0.3017) ...
+(1.064*a*10^6*X^0.4925/(Y*360*52.47))...
+(4.242*10^4*a*X^0.7952+(1.813*I*p*(n*X+1.2*Y)^0.861))/(52.47*360*Y)...
+(4.25*10^3*a*(n*X+1.2*Y))/(52.47*360*Y) +(5.042*10^3/360)*Y^(-0.1899)...
+ (0.1049/360)*Y^0.671 ;
% Initial Guess (Choose Initial Guesses):
x(1) = 100;
y(1) = 100;
e = 10^(-8); % Convergence Criteria
i = 1; % Iteration Counter
% Gradient and Hessian Computation %%%%%%%%%%%%%%%%%%
df_dx = diff(f, X);
df_dy = diff(f, Y);
% Gradient (Jacobian matrix)
J = [subs(df_dx,[X,Y], [x(1),y(1)]) subs(df_dy, [X,Y], [x(1),y(1)])];
ddf_ddx = diff(df_dx,X);
ddf_ddy = diff(df_dy,Y);
ddf_dxdy = diff(df_dx,Y);
ddf_ddx_1 = subs(ddf_ddx, [X,Y], [x(1),y(1)]);
ddf_ddy_1 = subs(ddf_ddy, [X,Y], [x(1),y(1)]);
ddf_dxdy_1 = subs(ddf_dxdy, [X,Y], [x(1),y(1)]);
H = [ddf_ddx_1, ddf_dxdy_1; ddf_dxdy_1, ddf_ddy_1]; % Hessian
S = inv(H); % Search Direction
% Optimization Condition:
while norm(J) > e
I = [x(i),y(i)]';
x(i+1) = I(1)-S(1,:)*J';
y(i+1) = I(2)-S(2,:)*J';
i = i+1;
J = [subs(df_dx,[X,Y], [x(i),y(i)]) subs(df_dy, [X,Y], [x(i),y(i)])]; %
Updated Jacobian
ddf_ddx_1 = subs(ddf_ddx, [X,Y], [x(i),y(i)]);
ddf_ddy_1 = subs(ddf_ddy, [X,Y], [x(i),y(i)]);
ddf_dxdy_1 = subs(ddf_dxdy, [X,Y], [x(i),y(i)]);
H = [ddf_ddx_1, ddf_dxdy_1; ddf_dxdy_1, ddf_ddy_1]; % Updated Hessian
S = inv(H); % New Search Direction

end
% Result Table:`
Iter = 1:i;
Tanker_Size = x';
Refinery_Capacity= y';
Iterations = Iter';
T = table(Iterations,Tanker_Size,Refinery_Capacity);
% Plots:
figure(1)
fcontour(f,'Fill','On');
xlim([0 500000]);
ylim([0 200000]);
colorbar('Ticks',[10,12,14,16,18,20],'TickLabels',
{'10','12','14','16','18','20'})

hold on
plot(x,y,'-
co','LineWidth',2,'MarkerFaceColor','red','MarkerEdgeColor','green','Marker
Size',8);
xlabel('Optimum Tanker Size,t (kL)\rightarrow ', 'FontSize', 14);
ylabel('Optimum Refinery Size,q (bbl/day)\rightarrow ', 'FontSize', 14);
grid on;
text(461000, 179790 ,'X^{*}','color','w','FontSize',13,'FontWeight','Bold')
% Output:
fprintf('Initial Objective Function Value: %d\n\n',subs(f,[X,Y],
[x(1),y(1)]));
if (norm(J) < e)
fprintf('Minimum succesfully obtained...\n\n');
end
fprintf('Number of Iterations for Convergence: %d\n\n', i);
disp('*******************************************************')
fprintf('Optimum Tanker Size (t): %-10.6f kL or %-10.6f bbl\n', x(i),
x(i)*(6.29));

fprintf('Optimum Refinery Size (q): %-10.6f bbl/day\n', y(i));


fprintf('Objective Function Minimum Value after Optimization:\n cost of
refined oil %f $/kL \n\n',subs(f,[X,Y],[x(i),y(i)]));
disp('*******************************************************')
disp(T)

Output:
Plot:

Q2. Matlab Script:

clc
close all
clear all

% given data
T = [-36.7,-19.6,-11.5,-2.6,7.6,15.4,26.1,42.2,60.6,80.1];
P = [1,5,10,20,40,60,100,200,400,760];

%%% linspace(x1,x2,n) generates n points between x1 and x2


t = linspace(-36,80.1,100);
%%% coefficients has been obtained by first and last point
s = 10.^(8.712734 - (2060.126097./(t+273.15))) ;
%%%%%%%%%%%%%%%%% PLOT %%%%%%%%%%%%%%
plot(T,P,'o','LineWidth',2,'MarkerFaceColor','red','MarkerEdgeColor','green
','MarkerSize',8)
hold on
% to plot on same existing plot

plot(t,s,'color','blue','LineWidth',2)
legend('Data Points', 'Curve Fit','FontSize', 14)
xlabel('Temperature,T (^{0}C) \rightarrow','FontSize',
14,'FontWeight','Bold')
ylabel('Pressure,P (mmHg)\rightarrow','FontSize', 14,'FontWeight','Bold')
xlim([-40 90]);
ylim([0 800]);

Plot:

Q3. Matlab Script:


clc
close all
clear all

f=@(t)8*exp(-.1*t.^2); % this is the function of the given released date


FractionUsed = integral(f,0,24); % calculating the amount of drug released
in 24 hour
RemaingDrugFaction=(100-FractionUsed)/100 % calculating the fraction of the
drug remaining after 24 hour
Result:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy