Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to do Nonlinear Regression coding in Matlab?

Status
Not open for further replies.

rahul.6sept

Full Member level 5
Joined
Nov 17, 2006
Messages
243
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
Guwahati, India
Activity points
2,889
Hi,
I've written a code in Matlab for nonlinear regression. But it is not executing. I'm attaching the same here. I want to calculate the value for kmax and ks in the code.
Code:
% To determine the value of Kmax and Ks for the model of bacteria growth
% given by      mu=(kmax*c^2)/(ks+c^2)
% can be rewritten as
% log(mu)=log(kmax*c^2)-log(ks+c^2)
% log(mu)=log(kmax)+2log(c)-2log(ks)*log(c)
% y = a0+a1*x+a2*u

         
mu=[1.10 3.34 5.29 6.66 7.58 8.18 8.60 8.89]; 
C=[0.5; 1.0; 1.5; 2.0; 2.5; 3.0; 3.5; 4.0];
C=repmat(C,1,1);
N=length(C);
xData=C;
yData=reshape(mu,8,1);
%% Calculate Linear Regression and plot
x=2*log(xData);
u=log(xData);

X=[ones(N,1),x,u];
Y=log(yData);

phi=inv(X'*X)*X'*Y;

a0=exp(phi(1));
a1=phi(2);
a2=phi(3);
phi_guess=[1;1];
phi_lsq=lsqnonlin(@(phi) mylsqnonlin(phi,x,y),phi_guess);



The function file is here below:

Code:
function [y,ks,kmax] = mylsqnonlin(phi,x,y,u)
% Get parameters
a0=phi(1);
a1=phi(2);
%a2=phi(3);

%% Calculation of the values of kmax & ks
y = a0+a1*x+a2*u ;
ks=-0.5*exp(a2);
kmax=exp(a0);

end


I'm getting the value of phi as NaN. It should give value as 1x3 matrix.




Rahul
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top