MP Matlab Codes
MP Matlab Codes
SOLUTION:
Matlab Code:
clc
clear all
load water_in_channel.txt
time_day1=water_in_channel(12:17,2);
height_day1=water_in_channel(12:17,4);
t=time_day1;
h=height_day1;
n=length(t);
H=0;
T=0630;
fprintf('i z H\n')
for i=1:n
z=1;
for j=1:n
if j~=i
z=z*(T-t(j))/(t(i)-t(j));
end
end
H=H+h(i)*z;
fprintf('%d %f %f\n',i,z,H)
end
fprintf('\n Height of water on DAY 1 at 0630H = %f\n',H)
Output:
i z H
1 0.001473 0.022834
2 -0.128149 -2.283846
3 0.866597 58.464594
4 0.271654 98.832412
5 -0.017927 93.866770
6 0.006351 96.159531
Matlab Code:
clear all
clc
syms a b x a0 A
%%Given
display('GIVEN : A = alpha*B*exp(beta*B)');
A = [0.75; 1.25; 1.45; 1.25; 0.85; 0.55; 0.35; 0.28; 0.18];
B = [0.1; 0.2; 0.4; 0.6; 0.9; 1.3; 1.5; 1.7; 1.8];
ConcData = table(A,B)
x0 =[1;1;1;1;1;1;1;1;1];
M =[x0,B];
Y =[reallog(0.75/0.1); reallog(1.25/0.2); reallog(1.45/0.4);
reallog(1.25/0.6); reallog(0.85/0.9); reallog(0.55/1.3);reallog(0.35/1.5);
reallog(0.28/1.7); reallog(0.18/1.8)];
n = M'*Y;
d =M'* M;
X = inv(d) * n
hold all
plot(B,A,'r*')
%plot the measured population
fplot(@(B) alpha*B*exp(beta*B),[0.1,1.8],'b--')
%plot the approximation
title('Concentration of Polymer Configuration A in terms of Polymer B')
%set axis lables, title and legend
xlabel('B')
ylabel('ln(A/B)')
%%Answer
fprintf('The values of a and b are %0.4f/mmolar and %0.4f/mmolar,
respectivery.\n',alpha,beta);
fprintf('The concentration of A is %0.4f mmolar when the concentration of B
is 1 mmolar.\n',A);
Output:
GIVEN : A = alpha*B*exp(beta*B)
ConcData =
A B
____ ___
0.75 0.1
1.25 0.2
1.45 0.4
1.25 0.6
0.85 0.9
0.55 1.3
0.35 1.5
0.28 1.7
0.18 1.8
SOLUTION:
X =
2.268178502736422
-2.473308765704634
alpha =
9.661785859642892
beta =
-2.473308765704634
Matlab Code:
format long
tol = 0.001; %set a value for the accuracy
maxstep = 1000; %set maximum number of steps to run for
ans =
9.707577397721552
-2.499396853676382