How to find relationship between three data
7 views (last 30 days)
Show older comments
I have an excel data consisting of three columns. I want to find the relationship between the the data in equation form. Can anybody explain the process for it?
2 Comments
Answers (1)
Ayush
on 14 Nov 2023
Hi Kushagra,
I understand that you want to find the relation between the data in the equation form for the data consisting of three columns.
You can use linear regression, which is a statistical approach to model the relation between the dependent variable and one or more independent variables.
Suppose you have “x1” and “x2” representing the first and second columns of data respectively. While the dependent third column variable is given by “y”. You can use the backslash operator “\” which performs a least-squares regression to obtain the coefficients for each independent variable. Thus, you will get an equation for “y” with respect to “x1” and “x2”. You can refer the code below, where I have used this operator for small sample data:
% Example data
x1 = [1; 2; 3; 4; 5]; % Independent variable 1
x2 = [4; 4; 6; 8; 10]; % Independent variable 2
y = [7; 12; 18; 24; 30]; % Dependent variable
% Create the design matrix (X) by concatenating the independent variables
X = [x1, x2];
% Perform linear regression using the backslash operator (\)
coefficients = X \ y;
% Extract the coefficients for each independent variable
b1 = coefficients(1);
b2 = coefficients(2);
% Display the equation
equation = ['y = ', num2str(b1), ' * x1 + ', num2str(b2), ' * x2'];
disp('Equation:');
disp(equation);
For more information on linear regression and usage of “\” operator, you can refer the below link:
Regards,
Ayush
0 Comments
See Also
Categories
Find more on Linear 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!