How do I take natural logarithm of a set of datas and do a least square fitting and get an expression?
2 views (last 30 days)
Show older comments
I have a set of 3 datas. i.e. one set of dependent variables and 2 set of independent variables. I want to use natural logarithms on these datas and use least square fitting to obtain a relationship between these three set of datas
% Dependent varaibales:
psi_o= [1.0690 2.02 1.3474 1.3580 1.3966 1.6701 1.4901 1.669 1.476 2.848 1.3871 2.8008 3.0724 2.3614 2.7726];
psi_1= [1.0431 1.1251 0.9519 0.9691 0.9380 1.5003 1.2390 1.3260 1.2584 2.848 1.2260 1.9754 2.125 1.6842 2.098];
psi_2= [0.9819 0.9916 1.0444 0.9938 0.9807 1.3555 1.2052 1.227 1.1849 1.747 1.2106 1.5462 1.6876 1.5860 1.726];
psi_3= [1.015 0.9875 1.0682 1.0763 1.0021 1.295 1.119 1.1112 1.125 1.681 1.1667 1.6932 1.862 1.677 1.6443 ];
% Independent variables :
We= [8.518 9.903 16.473 22.68 26.214 58.84 78.77 117.76 138.37 184.842 193.155 272.054 327.49 443.05 615.34];
Lambda= [1 0.701 0.501 0.397];
Here, for the dependent variable data set 'psi_o ' the independent variables are the whole data set of 'We' and only for Lambda =1, likewise 'psi_1' corresponds to We and Lambda = 0.701, similarly for psi_2 ansd psi_3 it the whole data set We and only Lambda = 0.501 and 0.397 respectively.
So how do I take the logarithms of all the values and obtain a relationship between psi_1,2,3 ; We; Lambda through least square fitting?
4 Comments
Shree Charan
on 2 Jun 2023
% Dependent varaibales:
psi_o= [1.0690 2.02 1.3474 1.3580 1.3966 1.6701 1.4901 1.669 1.476 2.848 1.3871 2.8008 3.0724 2.3614 2.7726];
psi_1= [1.0431 1.1251 0.9519 0.9691 0.9380 1.5003 1.2390 1.3260 1.2584 2.848 1.2260 1.9754 2.125 1.6842 2.098];
psi_2= [0.9819 0.9916 1.0444 0.9938 0.9807 1.3555 1.2052 1.227 1.1849 1.747 1.2106 1.5462 1.6876 1.5860 1.726];
psi_3= [1.015 0.9875 1.0682 1.0763 1.0021 1.295 1.119 1.1112 1.125 1.681 1.1667 1.6932 1.862 1.677 1.6443 ];
% Independent variables :
We= [8.518 9.903 16.473 22.68 26.214 58.84 78.77 117.76 138.37 184.842 193.155 272.054 327.49 443.05 615.34];
lambda= [1 0.701 0.501 0.397];
log_psi_0 = log(psi_o);
log_psi_1 = log(psi_1);
log_psi_2 = log(psi_2);
log_psi_3 = log(psi_3);
log_We = log(We);
X(:,1) = lambda(1)*log_We;
X(:,2) = lambda(2)*log_We;
X(:,3) = lambda(3)*log_We;
X(:,4) = lambda(4)*log_We;
Y = [log_psi_0', log_psi_1', log_psi_2', log_psi_3'];
B = X\Y;
B should have the coefficients for the relationship between 'psi_o', 'psi_1', 'psi_2' and 'psi_3', however the rank of X =1 indicating some sort of dependancy among 'lambda' and 'We'.
Answers (0)
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!