# Least squares regression of a quadratic without bx term.

3 visualizzazioni (ultimi 30 giorni)
Wojciech Kalinowski il 23 Gen 2020
Risposto: Star Strider il 23 Gen 2020
Hi,
I'm trying to find the least squars regression formula and R squared value.
However, the data has to fit y=ax^2+c without the bx term, so polyfit will not work.
The two sets of data y and x are a 1x119 double vector.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Star Strider il 23 Gen 2020
Try this:
DM = [x(:).^2 ones(size(x(:)))]; % Design Matrix
B = DM \ y(:); % Parameters
yfit = DM * B; % Calculated Fit
SStot = sum((y-mean(y)).^2); % Total Sum-Of-Squares
SSres = sum((y(:)-yfit(:)).^2); % Residual Sum-Of-Squares
Rsq = 1-SSres/SStot; % R^2
To plot it:
figure
plot(x, y, 'p')
hold on
plot(x, yfit, '-r')
hold off
grid
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Regression in Help Center e File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by