how do i deduce the function using linear regression for a set of x and y values?
Show older comments
clc
clear all
load x2.txt
load y2.txt
x=[x2]
y=log([y2])
format long
b2=x\y
yCalc1 = b2*x;
scatter(x,y)
hold on
plot(x,yCalc1)
xlabel('X_2')
ylabel('Y_2')
title('Linear Regression Relation Between X2 & Y2')
This is what I am getting when i tried to use linear regression. Is there any way i can find the function this plot is tracing?
Accepted Answer
More Answers (1)
KSSV
on 2 Jan 2022
clc
clear all
load x2.txt
load y2.txt
x=x2 ;
y = log(y2) ;
% Use polyfit
p = polyfit(x,y,1) ;
yCalc1 = polyval(p,x) ;
scatter(x,y)
hold on
plot(x,yCalc1)
title(sprintf('y = %f*x+%f',p))
xlabel('X_2')
ylabel('Y_2')
1 Comment
Zaki Aslam
on 2 Jan 2022
Categories
Find more on Univariate Discrete Distributions 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!

