Parabola plot not displayed correctly
2 次查看(过去 30 天)
显示 更早的评论
I am trying to have a quadratic fit to my data.
X = randi(100,[40, 1])
Y = (2* (X.^2)) +(3*X) +(5);
X2 = [ones(size(X)) X X.^2]
m3 = X2 \ Y;
y3 = X2*m3;
scatter(X,Y);
hold on
plot(X,y3)
ylabel('Y')
title('y= ax^2+bx+c', 'FontSize',18)
hold off;
![untitled1.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/230276/untitled1.jpeg)
However, when I display the plot istead of a single parabolic fir I am getting multiple lines.
Please help. I experimented this while learning linear regression.
0 个评论
采纳的回答
KSSV
2019-7-18
You are suing the random numbers for demo.....you have to sort them before you use:
X = randi(100,[40, 1]) ;
X = sort(X) ;
Y = (2* (X.^2)) +(3*X) +(5);
X2 = [ones(size(X)) X X.^2]
m3 = X2 \ Y;
y3 = X2*m3;
scatter(X,Y);
hold on
plot(X,y3)
ylabel('Y')
title('y= ax^2+bx+c', 'FontSize',18)
hold off;
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!