# How to fit a quadratic function using the "minimizing the volume-weighted mean squared error"?

20 views (last 30 days)
Iris Li on 30 Apr 2018
Commented: Siyu Guo on 1 May 2018
Say I have a function y = a + b*x + c*x.^2 and I got matrixes x and y, and the weight w.
Estimate the parameters ( a, b and c) by minimizing the volume-weighted mean squared error?
i.e. to minimize [ sum (w. * ( y - yhat ).^2) / (sum w) ]

Siyu Guo on 30 Apr 2018
Edited: Siyu Guo on 30 Apr 2018
u = sqrt(w(:));
b1 = u;
b2 = u.*x(:);
b3 = u.*x(:).^2;
f = u.*y(:);
A = [dot(b1,b1) dot(b1,b2) dot(b1,b3);
dot(b1,b2) dot(b2,b2) dot(b2,b3);
dot(b1,b3) dot(b2,b3) dot(b3,b3)];
v = [dot(b1,f); dot(b2,f); dot(b3,f)];
p = A\v; % p(1) = a, p(2) = b, p(3) = c
Hope I haven't made mistakes. :)

Siyu Guo on 30 Apr 2018
I do not tempt fate. I simply didn't know this use of \. :)
John D'Errico on 30 Apr 2018
I admit that I often seem to be ranting about the use of a few numerical methods, taught by textbooks, by teachers, in courses, etc. The problem is that numerical analysis has changed relatively rapidly over the last 50 years. We have learned much in that time. But there are still bad memes that propagate, and never seem to die out. The problem is that students are taught a bad numerical method. They are taught that by a teacher who learned the same thing, from a textbook or paper written by someone who did not know any better. And then the student grows up, into a teacher, a mentor, etc. What do they tell their own students? Of course, they teach what they know as "truth". That it is provably poor is irrelevant. But these memes propagate forever. Taught from one person to another by word of mouth, by text. etc.
It never stops unless someone is out there, trying to intercept the bad ideas from propagating, explaining why they are actively bad, and explaining that there is a good solution.
So I tilt at windmills...
Siyu Guo on 1 May 2018
I'm looking forward to a numeric methods textbook written by you, :)

Iris Li on 1 May 2018
Thanks you two! I made some silly comments but learned a lot. :)

#### 1 Comment

Siyu Guo on 1 May 2018
Reckon we can both learn a lot from John, :)