epostma

1494 Reputation

19 Badges

17 years, 64 days
Maplesoft

Social Networks and Content at Maplesoft.com

I am the manager of the Mathematical Software Group, working mostly on the Maple library. I have been working at Maplesoft since 2007, mostly on the Statistics and Units packages and on contract work with industry users. My background is in abstract algebra, in which I completed a PhD at Eindhoven University of Technology. During my studies I was always searching for interesting questions at the crossroads of math and computer science. When I came to Canada in 2007, I had nothing but a work permit, some contacts at Maplesoft (whom I had met at a computer algebra conference a year earlier), and a plan to travel around beautiful Canada for a few months. Since Maplesoft is a company that solves more interesting math and computer science related questions than just about anywhere else, I was quite eager to join them, and after about three months, I could start.

MaplePrimes Activity


These are replies submitted by epostma

@sund0002: I took a look at the worksheet that you posted. This is somewhat tricky business; it looks like Maple has decided that the first line that it is complaining about consists of two separate halves, and the split between the two occurs in between "pp" and ":=". So Maple sees a line starting with ":=". It might be best to insert a new execution group there (using for example the ">" button on the toolbar, or hitting Ctrl-J or Ctrl-K) and retype that line.

The more difficult and more interesting question is how that split line came about. Do you have any theories?
I don't know too much about how the GUI works, but here's something that might help. In general, I think if you're working with "Maple Input" (the 1-D, "text-only", "red Maple" style of input, as opposed to the 2-D typeset input), it works most reliably if you insert new execution groups in one of the ways I describe above (with the ">" button, Ctrl-J, or Ctrl-K), and set Tools -> Options -> Display -> Input display to Maple notation.

I believe the new execution groups come about sort of automatically if you open a new "Worksheet"; if you create a "Document", you have to do it in one of the ways described above.

Hope this helps,

Erik Postma
Maplesoft.

@pagan : You're absolutely right - I stand corrected. The thing is, I started working with Maple shortly before the release of Maple 12, so for me it's essentially been true forever.

Erik.

@pagan : You're absolutely right - I stand corrected. The thing is, I started working with Maple shortly before the release of Maple 12, so for me it's essentially been true forever.

Erik.

@sund0002 : You typed data[.., 2] instead of Data[.., 2], and furthermore you can see that again you haven't loaded the Statistics and plots packages (as in this thread). Both of these are clear from what Maple prints as returned values: the Fit and pointplot calls just return unevaluated (the result still looks like Fit(...) and display(...)), and clearly the data[.., 2] that is returned looks very different from the thing that says 1 .. 18 Array.

As a general rule, looking at what Maple returns is a great first step to figuring out what's going on, possibly even before asking a question on MaplePrimes.

Erik Postma
Maplesoft.

@sund0002 : You typed data[.., 2] instead of Data[.., 2], and furthermore you can see that again you haven't loaded the Statistics and plots packages (as in this thread). Both of these are clear from what Maple prints as returned values: the Fit and pointplot calls just return unevaluated (the result still looks like Fit(...) and display(...)), and clearly the data[.., 2] that is returned looks very different from the thing that says 1 .. 18 Array.

As a general rule, looking at what Maple returns is a great first step to figuring out what's going on, possibly even before asking a question on MaplePrimes.

Erik Postma
Maplesoft.

Absolutely, pagan, that's what I would suggest as well. Tiny note: I think 'N*m' is redundant; AddSystem will use whatever the last unit for a given dimension is, so kN*m will override N*m (just as it will override the jouleSI returned by GetSystem).

Erik Postma
Maplesoft.

Absolutely, pagan, that's what I would suggest as well. Tiny note: I think 'N*m' is redundant; AddSystem will use whatever the last unit for a given dimension is, so kN*m will override N*m (just as it will override the jouleSI returned by GetSystem).

Erik Postma
Maplesoft.

A tiny optimization in the number of characters you need to type: you could use

V,C := Data[..,1], Data[..,2];

instead of your assignment. The defaults for start and end of a range in indexing are always the minimum and maximum valid values.

Erik Postma
Maplesoft.

A tiny optimization in the number of characters you need to type: you could use

V,C := Data[..,1], Data[..,2];

instead of your assignment. The defaults for start and end of a range in indexing are always the minimum and maximum valid values.

Erik Postma
Maplesoft.

@sund0002 : if I open your worksheet and hit the 'three exclamation marks' button in the tool bar, it all works except for the definitions of answer1 and plot1 (which is because you used X, Y there, instead of V, C). It looks like you didn't evaluate the line that says with(Statistics), because the Fit(...) command returns as Fit(...), which means it doesn't call Statistics[Fit].

As to your Excel question: I never work with Excel, but I know we have an ?ExcelTools package which can presumably do that, and also a data import assistant ("Tools" menu -> "Assistants" -> "Import Data ...") which can read Excel sheets.

Erik.

@sund0002 : if I open your worksheet and hit the 'three exclamation marks' button in the tool bar, it all works except for the definitions of answer1 and plot1 (which is because you used X, Y there, instead of V, C). It looks like you didn't evaluate the line that says with(Statistics), because the Fit(...) command returns as Fit(...), which means it doesn't call Statistics[Fit].

As to your Excel question: I never work with Excel, but I know we have an ?ExcelTools package which can presumably do that, and also a data import assistant ("Tools" menu -> "Assistants" -> "Import Data ...") which can read Excel sheets.

Erik.

@sund0002 : Again two reasons :)

  1. I think you meant b*x where you wrote bx in the first example.
  2. Now that you've made n a parameter, it's not linear in the parameters anymore. So now Maple chooses to use NonlinearFit as the fitting routine inside Fit. Nonlinear fitting may give results that are not as easily reproducible: Maple finds only a locally optimal set of parameter values, not a globally optimal one.
    For this reason it's highly recommended that you provide Maple with initial values for the parameters if you use nonlinear fitting. If you set infolevel[Statistics] := 1 or higher, then Fit prints whether it uses linear or nonlinear fitting.
    If you don't know what a good initial value could be, then I would suggest you guess a value for n (such as 1.25 from the linear fitting you showed above) and have Maple first perform the fit with n fixed (so that it can do linear fitting). Then use the results from that linear fitting run to provide inital values for the nonlinear fitting run.

Regarding your plotting question: it's easiest if you also ask for the leastsquaresfunction output, then plot that. So you would run

ans2 := Fit(a*x^1.25+b*x+c, V, C, x, output = [parametervalues]);
ans3 := Fit(a*x^n+b*x+c, V, C, x, output = [parametervalues, residualsumofsquares, leastsquaresfunction], initialvalues = [op(ans2[1]), n = 1.25]);
p2 := plot(ans3[3], x=0..200);

Hope this helps,

Erik.

@sund0002 : Again two reasons :)

  1. I think you meant b*x where you wrote bx in the first example.
  2. Now that you've made n a parameter, it's not linear in the parameters anymore. So now Maple chooses to use NonlinearFit as the fitting routine inside Fit. Nonlinear fitting may give results that are not as easily reproducible: Maple finds only a locally optimal set of parameter values, not a globally optimal one.
    For this reason it's highly recommended that you provide Maple with initial values for the parameters if you use nonlinear fitting. If you set infolevel[Statistics] := 1 or higher, then Fit prints whether it uses linear or nonlinear fitting.
    If you don't know what a good initial value could be, then I would suggest you guess a value for n (such as 1.25 from the linear fitting you showed above) and have Maple first perform the fit with n fixed (so that it can do linear fitting). Then use the results from that linear fitting run to provide inital values for the nonlinear fitting run.

Regarding your plotting question: it's easiest if you also ask for the leastsquaresfunction output, then plot that. So you would run

ans2 := Fit(a*x^1.25+b*x+c, V, C, x, output = [parametervalues]);
ans3 := Fit(a*x^n+b*x+c, V, C, x, output = [parametervalues, residualsumofsquares, leastsquaresfunction], initialvalues = [op(ans2[1]), n = 1.25]);
p2 := plot(ans3[3], x=0..200);

Hope this helps,

Erik.

@sund0002 : Two reasons.

  1. Fit and LinearFit (and NonlinearFit) are commands in the Statistics package, so you either need to type with(Statistics); before you run them, or you need to give their "full" name: Statistics[Fit], Statistics[LinearFit], etc. (or equivalently, Statistics:-Fit etc.)
  2. You typed a*V^2+b*v instead of a*v^2+b*v. The difference between V (a vector) and v (a variable) is important.

Hope this helps,

Erik.

@sund0002 : Two reasons.

  1. Fit and LinearFit (and NonlinearFit) are commands in the Statistics package, so you either need to type with(Statistics); before you run them, or you need to give their "full" name: Statistics[Fit], Statistics[LinearFit], etc. (or equivalently, Statistics:-Fit etc.)
  2. You typed a*V^2+b*v instead of a*v^2+b*v. The difference between V (a vector) and v (a variable) is important.

Hope this helps,

Erik.

First 10 11 12 13 14 15 16 Last Page 12 of 21