linearity
2 ビュー (過去 30 日間)
古いコメントを表示
how to know that the graphical plot is linear till what extend? and i need to program for the same with the matlab command
1 件のコメント
Walter Roberson
2012 年 6 月 12 日
All plots are linear to within some error measure. You need to be clearer about your goals.
回答 (1 件)
Divyam
2024 年 10 月 30 日
Considering that you are plotting data and trying to determine linearity based on how well the data fits a linear model. Calculating the
value for the data and a linear model can help you determine the extent of its linearity.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1800720/image.png)
% Using sample data for x and y
x = linspace(0, 10, 100); % Independent variable
y = 2 * x + 3 + randn(size(x)); % Linear relationship with some noise
% Fit a linear model
p = polyfit(x, y, 1);
y_fit = polyval(p, x);
% Calculate R^2
SS_res = sum((y - y_fit).^2); % Residual sum of squares
SS_tot = sum((y - mean(y)).^2); % Total sum of squares
R_squared = 1 - (SS_res / SS_tot);
% Display R^2 value
fprintf('The coefficient of determination (R^2) is: %.2f\n', R_squared);
% Determine extent of linearity
threshold = 0.95;
if R_squared >= threshold
fprintf('The plot is linear to a high degree (R^2 >= %.2f).\n', threshold);
else
fprintf('The plot is not linear to a high degree (R^2 < %.2f).\n', threshold);
end
Note: an
value close to 1 determines a strong linear relationship.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1800725/image.png)
For more information regarding the
value, you can refer to the theoretical section of this documentation: https://www.mathworks.com/help/stats/coefficient-of-determination-r-squared.html
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1800730/image.png)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!