Since nobody has yet stated it in just so many words, I will add that `=` does not by itself bring about assignment in Maple.
So, it is not true that, "The symbol = means assignment." Without qualification an assertion like that is completely general. But since it isn't true in Maple in particular, then it also isn't always true.
Assignments in Maple are done using a `:=` statement, or using the `assign` operator.
As for what `=` can in fact mean in Maple, please see other replies to this subthread whose points I won't repeat here.
acer
The procedure Rsquared below could allow you to compute R^2 for data appearing in the first and second columns of a Matrix and for a given fitting formula in variable t.
Rsquared := proc( formula, T::symbol, m::Matrix )
local N, ybar, SS_err, SS_tot, SS_reg;
Digits:=trunc(evalhf(Digits));
N := op([1,1],m);
ybar := add( m[i,2], i=1..N )/N;
SS_tot := add( ( m[i,2] - ybar )^2, i=1..N );
SS_reg := add( ( eval(formula,T=m[i,1]) - ybar )^2, i=1..N );
SS_err := add( ( m[i,2] - eval(formula,T=m[i,1]) )^2, i=1..N );
return 1-SS_err/SS_tot;
end proc:
M := Matrix(6,2, [[1,2],[2,3],[3,4.8],[5,10.2],[6,30.9]] );
form := 0.888 + 0.606*exp(0.649*t);
Rsquared( form, t, M );
You could fix it up to do proper argument checking and validation. Comments could be added to the code. Or you could just examine it and compare to the formulas on that web-page, and try and figure out a bit more of how the Maple programming language works.
acer
The procedure Rsquared below could allow you to compute R^2 for data appearing in the first and second columns of a Matrix and for a given fitting formula in variable t.
Rsquared := proc( formula, T::symbol, m::Matrix )
local N, ybar, SS_err, SS_tot, SS_reg;
Digits:=trunc(evalhf(Digits));
N := op([1,1],m);
ybar := add( m[i,2], i=1..N )/N;
SS_tot := add( ( m[i,2] - ybar )^2, i=1..N );
SS_reg := add( ( eval(formula,T=m[i,1]) - ybar )^2, i=1..N );
SS_err := add( ( m[i,2] - eval(formula,T=m[i,1]) )^2, i=1..N );
return 1-SS_err/SS_tot;
end proc:
M := Matrix(6,2, [[1,2],[2,3],[3,4.8],[5,10.2],[6,30.9]] );
form := 0.888 + 0.606*exp(0.649*t);
Rsquared( form, t, M );
You could fix it up to do proper argument checking and validation. Comments could be added to the code. Or you could just examine it and compare to the formulas on that web-page, and try and figure out a bit more of how the Maple programming language works.
acer
So, you may be interested in the so-called "coefficient of determination", or R^2.
See
this link for details and explanations.
What I showed before is the residual sum of squares, which that page describes as its SS_err term. That pages also gives some formulae for R^2. Perhaps you would like to use the formula which computes R^2 via regression sum of squares.
If your X and Y data lie in the first and second columns of Matrix M, then in your code you can access the entries as M[i,1] instead of X[i] and M[i,2] instead of Y[i]. That saves your having to form the X and Y Vectors explicitly.
acer
So, you may be interested in the so-called "coefficient of determination", or R^2.
See
this link for details and explanations.
What I showed before is the residual sum of squares, which that page describes as its SS_err term. That pages also gives some formulae for R^2. Perhaps you would like to use the formula which computes R^2 via regression sum of squares.
If your X and Y data lie in the first and second columns of Matrix M, then in your code you can access the entries as M[i,1] instead of X[i] and M[i,2] instead of Y[i]. That saves your having to form the X and Y Vectors explicitly.
acer
The uploaded file has,
p*n+s = `mod`(0, a)
Did you perhaps intend either of these forms below?
> restart:
> s := 3: p := 1: a := 4: t := 0:
> for n to 10 do
> if `mod`(p*n+s,a) = 0
> then t := t+1
> else p*n+s
> end if;
> end do;
> t;
3
Or,
> restart:
> s := 3: p := 1: a := 4: t := 0:
> for n to 10 do
> if p*n+s mod a = 0
> then t := t+1
> else p*n+s
> end if;
> end do;
> t;
3
acer
Exactly, Scott. It's not currently possible to get the symbol to display correctly in both places; Subject line and Recent comments sidebar. It's nice to know that Will's looking at some issues with this site.
As for the motivation, I was actually trying to represent a key press in a not so unusual way, eg. -. But it's also pretty natural to imagine that the less-than symbol might be wanted, at some point, in the title of a posting on a discussion site for mathematical software.
acer
It appears as if the comments (starting with # symbol) and the code in the problem area of your Document are being interpreted by Maple as being all on one line. So anything that appeared after the comment symbol, including the code, was being treated as part of one big long comment. As one big comment, it wouldn't execute. At least, that's what it looked like after conversion to 1D input, and that would exactly match the behaviour being seen.
I suggest one of two possible ways to get around this problematic behaviour. The first is to write your code in 1D Math input, preferably in a Worksheet not a Document, where such discrepancies are very much rarer. (You can even change preferences, globally for future sessions, for both those aspects.) The second choice is to use text input for comments when using 2D Math and Documents.
The max() routine will give the maximum of an expression sequence. For a list L, the expression sequence of its contents is op(L). The printf() routine can format and print things nicely. It works much like it does in the C language. There is an additional qualifier, %a, which stands for algebraic (I think). For your code and list W, it could be like this
printf("Max = %a\n", max(op(W)));
acer
It appears as if the comments (starting with # symbol) and the code in the problem area of your Document are being interpreted by Maple as being all on one line. So anything that appeared after the comment symbol, including the code, was being treated as part of one big long comment. As one big comment, it wouldn't execute. At least, that's what it looked like after conversion to 1D input, and that would exactly match the behaviour being seen.
I suggest one of two possible ways to get around this problematic behaviour. The first is to write your code in 1D Math input, preferably in a Worksheet not a Document, where such discrepancies are very much rarer. (You can even change preferences, globally for future sessions, for both those aspects.) The second choice is to use text input for comments when using 2D Math and Documents.
The max() routine will give the maximum of an expression sequence. For a list L, the expression sequence of its contents is op(L). The printf() routine can format and print things nicely. It works much like it does in the C language. There is an additional qualifier, %a, which stands for algebraic (I think). For your code and list W, it could be like this
printf("Max = %a\n", max(op(W)));
acer
Please ignore. This was an accidental duplicate post.
acer
Please ignore. This was an accidental duplicate post.
acer
I don't know anything about pasting into mapleprimes, sorry.
But the other issue, about what is printed, I can answer.
You code does not comprise a "routine". It's not a Maple procedure. It's what's known as "top-level" code.
As such, it is governed by Maple's printing rules. These can be changed (at the top-level, and also from within procedures) by using the printlevel setting. See ?printlevel for details.
The default is printlevel=1. So, with a for-do and if-then embedded within it, then anything occuring inside the `then` or `else` sections won't normally get printed.
But, now, set printlevel:=2 and run that code again. Both the 7 and the 9 are printed.
Of course, this is all just control of the display. Assignments and such get done regardless of whether their results are displayed.
Some people like to use print or printf statements to get certain things, and only certain things, printed by their code. Others make use of the fact that procedures, when run, will cause their returning values to be printed. I find that sufficient myself, and would recommend using procedures for even small tasks (for this, and lots of other reasons besides).
acer
I don't know anything about pasting into mapleprimes, sorry.
But the other issue, about what is printed, I can answer.
You code does not comprise a "routine". It's not a Maple procedure. It's what's known as "top-level" code.
As such, it is governed by Maple's printing rules. These can be changed (at the top-level, and also from within procedures) by using the printlevel setting. See ?printlevel for details.
The default is printlevel=1. So, with a for-do and if-then embedded within it, then anything occuring inside the `then` or `else` sections won't normally get printed.
But, now, set printlevel:=2 and run that code again. Both the 7 and the 9 are printed.
Of course, this is all just control of the display. Assignments and such get done regardless of whether their results are displayed.
Some people like to use print or printf statements to get certain things, and only certain things, printed by their code. Others make use of the fact that procedures, when run, will cause their returning values to be printed. I find that sufficient myself, and would recommend using procedures for even small tasks (for this, and lots of other reasons besides).
acer
The confusion is quite understandable. The Shift-Enter shortcut is not specific to 2D Math input.
acer
Hit Shift and Enter at the same time.
See the help-page, ?shortcut_keys,windows
acer