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
- :
- Trouble with nonlinear curve fitting functions

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

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

04-07-2021
02:19 PM

04-07-2021
02:19 PM

Trouble with nonlinear curve fitting functions

I am moving some calculations from Octave (open-source MATLAB clone) for Prime 7.0. One of the calculations involves fitting a double exponential pulse to measured data. In Octave/MATLAB I use the lsqcurvefit function, which executes very quickly and appears to give me reasonable answers.

I am trying to find an equivalent function in MathCAD Prime. I tried genfit and LeastSquaresFit - for genfit I get a regression not converging error, for LeastSquaresFit I get a floating point error. I even tried using the output of my MATLAB calculation as the guess value and still get these errors.

Here is a screenshot showing the function I am trying to fit, the guess value (which is the output from MATLAB), and a plot of the data and the fitting function using the guess value.

I assume I am doing something fundamentally wrong here. In MATLAB I can start with a guess value wildly in error and still get an answer.

Labels:

6 REPLIES 6

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

04-07-2021
02:53 PM

04-07-2021
02:53 PM

Re: Trouble with nonlinear curve fitting functions

Send please your data X and Y vectors or/and thw Prime sheet.

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

04-07-2021
02:56 PM

04-07-2021
02:56 PM

Re: Trouble with nonlinear curve fitting functions

Here is the sheet and the data file.

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

04-07-2021
03:07 PM

04-07-2021
03:07 PM

Re: Trouble with nonlinear curve fitting functions

I finally figured how to scroll down in the numeric display of the vector (very different between 15 and Prime) and found an format error in my input data. The genfit function appear to work now.

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

04-07-2021
09:28 PM

04-07-2021
09:28 PM

Re: Trouble with nonlinear curve fitting functions

It looks to me that genfit works pretty well using the data you provided without modifications.

The values are not the same but similar to the ones you have from Octave.

You also can calculate the values using a solve block with minerr:

LeastSquaresFit works, too, but it takes very long to finish the calculation:

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

04-08-2021
12:30 AM

04-08-2021
12:30 AM

Re: Trouble with nonlinear curve fitting functions

Thanks. Turns out my mistake was taking the time from column 0 and the voltage from column 3 without realizing that columns 2 and 3 had fewer data points so one of my vectors had a bunch of NaN entries.

I am just starting with Prime, had been using old MathCAD from the DOS version up through 15. I run into a lot of things that are slightly different in Prime...

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

04-08-2021
05:36 AM

04-08-2021
05:36 AM

Re: Trouble with nonlinear curve fitting functions

I run into a lot of things that are slightly different in Prime...

"slightly different" - this is a very well-intentioned euphemism 🙂

In fact, Prime is far inferior to the old Mathcad in terms of functionality and ease of use. And when it comes to the scrolling in large matrices you mentioned earlier, that's just terrible. It looks like a childish programmer has played around with a programmers toolbox without thinking too much.

Admittedly, Prime also has a few advantages (such as entering matrices or using different units in a matrix, as with the vector beta). But the bottom line is that Prime is a long way from being compared to Mathcad.