topic Re: Nonlinear curve fitting of piecewise-defined function in PTC Mathcad
https://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407605#M159746
<HTML><HEAD></HEAD><BODY><BLOCKQUOTE><TABLE border="1"><TBODY><TR><TD>
<P>Don Warren wrote:</P>
<P></P>
<P>As suggested by the title, I'm attempting to fit a piecewise-defined curve to a set of data points. This is also the first time I have used Mathcad, so it is exceedingly likely I'm missing something obvious. My worksheet is attached to this post.</P>
<P style="min-height: 8pt; padding: 0px;"></P>
<P>I'm attempting to follow the example at <A class="jive-link-external-small" href="http://www.phys.uconn.edu/~hamilton/phys258/P/genfit.pdf" rel="nofollow" target="_blank">http://www.phys.uconn.edu/~hamilton/phys258/P/genfit.pdf</A>, but when I call the genfit routine, I get the error "This value must be a function".</P>
<P style="min-height: 8pt; padding: 0px;"></P>
<P>So, <STRONG>question number 1:</STRONG> what is this error message trying to tell me, and how can I resolve it?</P>
</TD></TR></TBODY></TABLE></BLOCKQUOTE><P>What it's telling you, after using the error trace facility, is that you have type d(...) in several instances. Mathcad interprets this to mean that d is a function; you need to explicitly type the multiplication operator between d and the parenthesis.</P><P></P><P>After this, you have another slight problem. Your guess values for x = 0, give F(x) = complex, which genfit won't handle. Looking at your expression for f, this is because with b and e positive, you will get roots of negative numbers. The fix is to make b and e negative. It should work then. See attached modification to your worksheet.</P><P></P><P>Question 2: Don't have time to look at it, unfortunately.</P><P></P><P>Question 3: It appears as if Mathcad can't directly symbolically solve conditional functions. You can break the function up and take the derivatives of each part, though ... but not a very good choice. Probably imposes because the results, without much thought about constraints, could turn out to be horrendously messy!</P><P></P><P>Interestingly, the example worksheet you were working from doesn't work as written in Prime, because the genfit solver algorithm (an Optimized L-M) is quite fussy about initial values. In Mathcad 15 you have the option to choose an ordinary L-M solver, which gives the expected answer. In Prime you have to amend the guess value to [500, -0.1]</P><P></P><P>Stuart</P></BODY></HTML>Fri, 25 Sep 2015 14:31:23 GMTStuartBruff2015-09-25T14:31:23ZNonlinear curve fitting of piecewise-defined function
https://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407602#M159743
As suggested by the title, I'm attempting to fit a piecewise-defined curve to a set of data points. This is also the first time I have used Mathcad, so it is exceedingly likely I'm missing something obvious. My worksheet is attached to this post.I'm attempting to followThu, 03 May 2018 15:06:18 GMThttps://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407602#M159743dwarren2018-05-03T15:06:18ZRe: Nonlinear curve fitting of piecewise-defined function
https://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407603#M159744
<HTML><HEAD></HEAD><BODY><P>Unfortunately, your worksheet is in Prime 3.1 format, and I have Prime 3.0, which can't read it (ridiculous, but true: Prime file formats are not even compatible within a major release version, and Prime cannot save a file back to any earlier version). So I can't answer question 1. For question 2, you would be better off using a solve block with minerr, which can handle constraints. The answer to question 3 is yes, in principle. Without seeing the worksheet I can't say why you are getting an error though.</P><P></P><P>Is there a particular reason you are using Mathcad Prime rather than Mathcad 15?</P></BODY></HTML>Fri, 25 Sep 2015 13:59:55 GMThttps://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407603#M159744RichardJ2015-09-25T13:59:55ZRe: Nonlinear curve fitting of piecewise-defined function
https://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407604#M159745
<HTML><HEAD></HEAD><BODY><BLOCKQUOTE><TABLE border="1"><TBODY><TR><TD>
<P>Richard Jackson wrote:</P>
<P></P>
<P>Unfortunately, your worksheet is in Prime 3.1 format, and I have Prime 3.0, which can't read it (ridiculous, but true: Prime file formats are not even compatible within a major release version, and Prime cannot save a file back to any earlier version).</P>
</TD></TR></TBODY></TABLE></BLOCKQUOTE><P></P><P>I am waiting from PTC Mathcad team for a new technology: We cannot read Prime 3.0 files in Mathcad 3.1 and 4.0 <IMG src="https://community.ptc.com/legacyfs/online/emoticons/wink.png" /></P></BODY></HTML>Fri, 25 Sep 2015 14:20:45 GMThttps://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407604#M159745ValeryOchkov2015-09-25T14:20:45ZRe: Nonlinear curve fitting of piecewise-defined function
https://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407605#M159746
<HTML><HEAD></HEAD><BODY><BLOCKQUOTE><TABLE border="1"><TBODY><TR><TD>
<P>Don Warren wrote:</P>
<P></P>
<P>As suggested by the title, I'm attempting to fit a piecewise-defined curve to a set of data points. This is also the first time I have used Mathcad, so it is exceedingly likely I'm missing something obvious. My worksheet is attached to this post.</P>
<P style="min-height: 8pt; padding: 0px;"></P>
<P>I'm attempting to follow the example at <A class="jive-link-external-small" href="http://www.phys.uconn.edu/~hamilton/phys258/P/genfit.pdf" rel="nofollow" target="_blank">http://www.phys.uconn.edu/~hamilton/phys258/P/genfit.pdf</A>, but when I call the genfit routine, I get the error "This value must be a function".</P>
<P style="min-height: 8pt; padding: 0px;"></P>
<P>So, <STRONG>question number 1:</STRONG> what is this error message trying to tell me, and how can I resolve it?</P>
</TD></TR></TBODY></TABLE></BLOCKQUOTE><P>What it's telling you, after using the error trace facility, is that you have type d(...) in several instances. Mathcad interprets this to mean that d is a function; you need to explicitly type the multiplication operator between d and the parenthesis.</P><P></P><P>After this, you have another slight problem. Your guess values for x = 0, give F(x) = complex, which genfit won't handle. Looking at your expression for f, this is because with b and e positive, you will get roots of negative numbers. The fix is to make b and e negative. It should work then. See attached modification to your worksheet.</P><P></P><P>Question 2: Don't have time to look at it, unfortunately.</P><P></P><P>Question 3: It appears as if Mathcad can't directly symbolically solve conditional functions. You can break the function up and take the derivatives of each part, though ... but not a very good choice. Probably imposes because the results, without much thought about constraints, could turn out to be horrendously messy!</P><P></P><P>Interestingly, the example worksheet you were working from doesn't work as written in Prime, because the genfit solver algorithm (an Optimized L-M) is quite fussy about initial values. In Mathcad 15 you have the option to choose an ordinary L-M solver, which gives the expected answer. In Prime you have to amend the guess value to [500, -0.1]</P><P></P><P>Stuart</P></BODY></HTML>Fri, 25 Sep 2015 14:31:23 GMThttps://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407605#M159746StuartBruff2015-09-25T14:31:23ZRe: Nonlinear curve fitting of piecewise-defined function
https://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407606#M159747
<HTML><HEAD></HEAD><BODY><BLOCKQUOTE><TABLE border="1"><TBODY><TR><TD>
<P>Richard Jackson wrote:</P>
<P></P>
<P>Is there a particular reason you are using Mathcad Prime rather than Mathcad 15?</P>
</TD></TR></TBODY></TABLE></BLOCKQUOTE><P></P><P>This is a question I *can* answer. I just bought Mathcad as part of starting a new postdoc (my Ph.D. advisor has been using Mathcad since its single-digit version number days). When I searched on PTC's website, I didn't find a way to buy Mathcad 15. After further looking just now I still don't. If 15 is more powerful than Prime (and is available for purchase) then maybe I should contact PTC about upgrading to a potentially more useful version.</P></BODY></HTML>Fri, 25 Sep 2015 16:55:58 GMThttps://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407606#M159747dwarren2015-09-25T16:55:58ZRe: Nonlinear curve fitting of piecewise-defined function
https://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407607#M159748
<HTML><HEAD></HEAD><BODY><P>What is this error trace facility you're referring to? Is it a feature that exists in Prime 3.1? (The first Google hit suggested that right-clicking on the offending function's name should bring up a ... something ... but that doesn't happen.) On the other hand, Prime 3.1 also has a button for converting xmcd files that is permanently grayed-out and unusable, so this may be something of a trend. I really should look into Mathcad 15, whatever that is.</P></BODY></HTML>Fri, 25 Sep 2015 17:02:23 GMThttps://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407607#M159748dwarren2015-09-25T17:02:23ZRe: Nonlinear curve fitting of piecewise-defined function
https://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407608#M159749
<HTML><HEAD></HEAD><BODY><BLOCKQUOTE><TABLE border="1"><TBODY><TR><TD>
<P>Don Warren wrote:</P>
<P></P>
<P>What is this error trace facility you're referring to? Is it a feature that exists in Prime 3.1? (The first Google hit suggested that right-clicking on the offending function's name should bring up a ... something ... but that doesn't happen.) .</P>
</TD></TR></TBODY></TABLE></BLOCKQUOTE><P>Look on the Calculation tab in the Ribbon. You should see a collection of slightly washed-out red "video" buttons in the Error Tracing group. Click on the expression with an error and the buttons should get brighter (they don't always; it depends on whether the error tracing facility can look back any further than the expression with the error). You then click on the appropriate Error Trace button to follow the calculations back to where Prime thinks the problem originated. Your next task is then to work out what the sometimes cryptic error messages actually mean! <IMG src="https://community.ptc.com/legacyfs/online/emoticons/devil.png" /> </P><P></P><P>The right-click Google suggestion refers to error tracing in Mathcad 15. I actually prefer the Prime method of tracing errors, but I do miss M15's debug window.</P><P></P><BLOCKQUOTE><TABLE border="1"><TBODY><TR><TD>
<P>On the other hand, Prime 3.1 also has a button for converting xmcd files that is permanently grayed-out and unusable, so this may be something of a trend. I really should look into Mathcad 15, whatever that is.</P>
</TD></TR></TBODY></TABLE></BLOCKQUOTE><P>You need to have Mathcad 15 installed for the xmcd converter to work. If you have a full Prime 3.1, rather than Prime Express, you are automatically licenced for a copy of Mathcad 15. If you haven't got it with your Prime distribution, then you can download it from </P><P></P><P><A class="jive-link-external-small" href="http://www.ptc.com/product/mathcad/free-trial" rel="nofollow" target="_blank">http://www.ptc.com/product/mathcad/free-trial</A><SPAN>.</SPAN></P><P></P><P>You should definitely check it out, if only to make you realize what Prime is still missing compared to the original Mathcad.</P><P></P><P>... and, to be fair, to notice Prime's</P><P>significant improvements in matrix entry, </P><P>mixed unit arrays </P><P>and change from static type checking (a form of Nannyware introduced in Mathcad 12 that stopped some people from making unit errors at design time but really hacked off a number of experienced users by stopping them doing useful and interesting things)</P><P>Oh, and control-J for entering programming keywords .... </P><P></P><P>Stuart</P></BODY></HTML>Fri, 25 Sep 2015 17:22:35 GMThttps://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407608#M159749StuartBruff2015-09-25T17:22:35ZRe: Nonlinear curve fitting of piecewise-defined function
https://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407609#M159750
<HTML><HEAD></HEAD><BODY><P>Your license for Prime will also work for Mathcad 15, which you can download here: <A href="http://www.ptc.com/product/mathcad/free-trial/thank-you">http://www.ptc.com/product/mathcad/free-trial/thank-you</A></P><P></P><P>Mathcad 15 is more powerful than Prime in almost all respects.</P></BODY></HTML>Fri, 25 Sep 2015 17:51:09 GMThttps://community.ptc.com/t5/PTC-Mathcad/Nonlinear-curve-fitting-of-piecewise-defined-function/m-p/407609#M159750RichardJ2015-09-25T17:51:09Z