Matlab Modify the program to include seemingly nonlinear pow

[Matlab] Modify the program to include seemingly non-linear power equations and exponential equations.

Verify the matlab code is working by finding the coefficients for exponential growth of bacteria per unit volume presented in a culture after x hours.

y=ae-bx

So I calculated the coefficient for exponential growth to be .358 (meaning the number of bacterias will increase by 35.8% every hour)

The following code is provided:

clear all
x=[0;1;2;3;4;5;6]
y=[3.5;5.5;7;9;10;13;16]
n=size(x);
x1=[ones(n(1),1) x]
x1\'
b=inv(x1\'*x1)*(x1\'*y);
yp=b(1)+b(2)*x;
sx=((sum((x-mean(x)).^2))/(n(1)-1))^.5
std(x)
sy=((sum((y-mean(y)).^2))/(n(1)-1))^.5
std(y)
sxy=(sum((x-mean(x)).*(y-mean(y))))/(n(1)-1)
corr=sxy/(sx*sy)
covar=cov(x,y)
corr=covar(1,2)/(sx*sy)
plot(x,y,\'o\',x,yp,\'-\')
legend([\'y=\',num2str(b(1)),\'+\',num2str(b(2)),\'x, correlation=\',num2str(corr)]);

Which will produce a graph:

The code needs to be modified so it will show the growth of bacteria over time and should follow the format of this graph (including change the legend)

Hours(x) 0 1 2 3 4 5 6
Number(y) 32 47 65 92 132 190 275
16 O y 3.1964+1.9821x, comelation-0.9895 14 12 10 8 6 4 2 2 4

Solution

Matlab program :-

clear all
clc
x = [0;1;2;3;4;5;6];
% x(1) = 0 and y(1) = 32. So, a = y/exp(b*0) = y/1 = y = 32
% so,in this manner we can find \'a\'
a = 32;   
% x(7) = 6 any y(7) = 275. so, b = (1/x)*log(y/a) = (1/6)*log(275/a)
% by using this equation we can find \'b\'
b = (1/6)*log(275/a);
y = a.*exp(b.*x);
plot(x,y,\'o\')
hold on
plot(x,y)
legend([\'a = \',num2str(a),\', b = \',num2str(b),\' and\',\' y=\',num2str(a),\'*exp(\',num2str(b),\'*x)\']);

[Matlab] Modify the program to include seemingly non-linear power equations and exponential equations. Verify the matlab code is working by finding the coeffici

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site