Fitting a Quadratic Polynomial
Mostrar comentarios más antiguos
Hi,
I need help trying to fit a quadratic polynomial (see jpeg) to the data (SietusModel.mat) and find the:
1) the value of each coefficient
2) the R2 value
3) a plot of the residuals, labeling your axes
I have tried using, but I'm not too sure I'm on the right path:
X = [ones(length(SietusDataset),1) SietusDataset(:,1)];
gamma = (X'*X)^-1*X'*SietusDataset(:,2);
xtest = 0.1:0.1:4;
ypredict = gamma(1) + gamma(2)*xtest;
figure
plot(SietusDataset(:,1),SietusDataset(:,2),'o')
xlabel('Base Width (nm)')
ylabel('Survival (days)')
grid on
hold on
plot(xtest,ypredict,'.')
Thank You so much!
1 comentario
Since this is clearly a homework problem, whether you're on the right path or not depends on the constraints the instructor has placed on the solution submitted.
As far as "purely Matlab" goes, no, you're not on the right track at all in writing the explicit design matrix and inverting it...this is, in general, a very bad idea (tm) and there are a plethora of available functions designed for the purpose that can be used with better numeric properties and more or less in the way of the analysis results depending on which you choose.
What, specifically, satisfies the requirement of the assignment is, however, unknown.
BTW, kudos for posting work; quite often we only get the question. :)
ADDENDUM Meant to include the admonition that before you fit anything, plot the data to see if it even makes sense to consider doing so (homework assignment be d-d! :) ).
Respuestas (0)
Categorías
Más información sobre Polynomials en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!