cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

1-Newbie

## Attempt to curve fit a quadratic function using data points - Not working

Hey. So in my Computer Methods class we have to determine a least squares quadratic fit from given data points. I basically just followed an example he had in the book. I can get the right answers by hand but for some reason my mathcad values aren't evaluating correctly. The f(xi) values are supposed to be very similar if not the same as the yi values. That way the regression line fits with the yi plotted values. Someone please help? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
19-Tanzanite
(To:jmurphy)

A few problems. See the attached worksheet.

If you calculated [A]*[M]^(-1) by hand, then you are doing some rather novel matrix math

As an additional note, your fitted function would not normally be considered to be a quadratic fit, because you have no term in x. What you have is a parabola, which is to say a quadratic with the constant for the term in x set to zero.

10 REPLIES 10
19-Tanzanite
(To:jmurphy)

Please post the worksheet (click on "Use Advanced Editor" at the top right of the edit dialog). Pictures are hard to debug and we don't like having to retype everything. Also please explain in more detail what you mean by "I can get the right answers by hand". At what point in the calculations do Mathcad's numbers start to differ from the ones you calculate by hand?

One thing that may be a problem: the default origin for arrays in Mathcad is 0, not 1 (so a 5 element array has indices 0, 1, 2, 3, 4, not 1, 2, 3, 4, 5). Did you change the origin from the default?

1-Newbie
(To:RichardJ)

Oh ok, sorry I'll make sure to post the worksheet next time. New to this and didn't know it was possible haha. How do I add the worksheet now?

Yes, I have tried to change the origin from 1,2,3,4,5 to 0,1,2,3,4 completely by going through and aligning them all to the default origin for arrays. This didn't seem to work either though, because then in the summations I would get an error that said "the array index is invalid" even if i started at 0 or 1. I'll try again and double check that everything matches up.

For my hand calculations I think I just have different values for the summations in the matrices. When I do the hand calculations I use [A]*[M]^(-1) in order to solve for {C} where [M]{C}=[A]. Whereas when I evaluate on MathCad I use lsolve(M,A). I tried to type out C:= [A]*[M]^(-1) in MathCad, but then I get the error "array dimension do not match". So I do think it is a problem with my summations and probably my array index, but I can't seem to figure it out.

22-Sapphire II
(To:jmurphy)

Rather than try to alter your equations to fit the default Origin of 0, just type ORIGIN:=ou1 at the start of your worksheet. It makes life a lot easier if you're trying to implement a set of equations as you only have one set of bugs and typos to look for!

Stuart

19-Tanzanite
(To:StuartBruff)
 just type ORIGIN:=ou1

ORIGIN:=1 might work even better

Based on the picture, I don't think that alone will fix it though. There seems to be a mixture of ORIGIN=0 stuff and ORIGIN=1 stuff.

1-Newbie
(To:StuartBruff)

I'll keep that in mind, thanks!

1-Newbie
(To:RichardJ)

Ok I figured it out. Here is my worksheet. Right now it is oriented for the original array index of 0,1,2,3,4 but can easily be changed to what I have in the question if you prefer that. Thanks.

19-Tanzanite
(To:jmurphy)

A few problems. See the attached worksheet.

If you calculated [A]*[M]^(-1) by hand, then you are doing some rather novel matrix math

As an additional note, your fitted function would not normally be considered to be a quadratic fit, because you have no term in x. What you have is a parabola, which is to say a quadratic with the constant for the term in x set to zero.

1-Newbie
(To:RichardJ)

Awesome, thanks so much! I mean I just used the matrix function on my calculator to evaluate the matrix. Not all the way through, I'm not that committed to this homework problem haha.

Thanks so much! I totally get it now. You da bomb

19-Tanzanite
(To:jmurphy)
 I'm not that committed to this homework problem haha.

With that information, maybe I'm not that committed to any of your future homework problems. Haha.

1-Newbie
(To:RichardJ)

Nooooo ok I take it back. Definitely dedicated. I'm just utilizing my awe-inspiring logic to deduct that the matrix function on my calculator could save me time and effort for this problem, in contrast to doing the entire evaluation by hand. That's what MathCad is all about, eh? Thanks again for your help, I was able to do the other problems without any hiccups.

Announcements
Check out the latest