Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Attempt to curve fit a quadratic function using da...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
04:32 PM

03-21-2015
04:32 PM

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.

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
06:19 PM

03-21-2015
06:19 PM

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
04:51 PM

03-21-2015
04:51 PM

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

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?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
05:25 PM

03-21-2015
05:25 PM

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

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.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
05:32 PM

03-21-2015
05:32 PM

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

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
05:36 PM

03-21-2015
05:36 PM

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

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.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
06:57 PM

03-21-2015
06:57 PM

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

I'll keep that in mind, thanks!

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
05:34 PM

03-21-2015
05:34 PM

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

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.

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
06:19 PM

03-21-2015
06:19 PM

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.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
07:01 PM

03-21-2015
07:01 PM

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

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
09:01 PM

03-21-2015
09:01 PM

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

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.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-21-2015
09:32 PM

03-21-2015
09:32 PM

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

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.