How can i plot the basic fitting line through the origin (0,0)?

21 ビュー (過去 30 日間)
praveen mandara
praveen mandara 2018 年 4 月 5 日
回答済み: Are Mjaavatten 2018 年 4 月 5 日
Information entered to the command window:
>> x=0:1.96:19.62; y=[0,1,3,11,25,38,52,66,78,93,106];
>> plot(x,y,'+')
>> xlabel('Load/N'); ylabel('Deflection/mm'); title('Measuring the Stiffness of the Spring');
The Figure plotted using the basic fitting linear option:
However I want my best fit line to go through the origin (0,0) without altering the data values or the scale of the axis.

回答 (1 件)

Are Mjaavatten
Are Mjaavatten 2018 年 4 月 5 日
You want to find the slope a of the line
that best fits your data. The least squares solution is to find the a that minimizes
In Matlab you can use the backslash operator to do this, after transposing your arrays to column vectors:
a = x'\y';
plot(x,y,'*',x,a*x)
See also the function polyfix in the Mathworks File Exchange.

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by