234 Reputation

18 years, 160 days

@Preben Alsholm    Thanks! Y...

Thanks! You are right!

kind regards,

Harrry

Thanks a lot!I was trying to figure out ...

Thanks a lot!

I was trying to figure out what the pattern is, but this code is really beautiful.

kind regards,

Harry Garst

@Preben Alsholm    Thanks for ...

Ten years ago I wrote some code to  deals with the weird scientific notation used in the to be imported textfile (D used instead of E). However, now I see that Maple has no problems parsing the data and the following code works.

restart; with(LinearAlgebra); with(FileTools);with(plots);
file1 := "C:/path/ULSlx3.txt";
Lambda := Matrix(5, 1);
for row to RowDimension(Lambda) do
end do;
Lambda;

So I don't need the old code no more.

old code:

local i,j,r,H,v,temp,c,k;
H:=ImportMatrix(B, delimiter="", datatype=string):
v := Vector(0);
ColumnDimension(H); RowDimension(H);
for i to RowDimension(H) do
H[i, 1] := StringTools[SubstituteAll](H[i, 1], "D", "E");
H[i, 1] := StringTools[SubstituteAll](H[i, 1], "+", "");
temp := sscanf(H[i, 1], "%f %f %f %f %f %f");
convert(temp, Vector);
v := Vector([v, temp]) end do;
eval(v); Dimension(v);
r := RowDimension(Lambda); c := ColumnDimension(Lambda); k := 0;
for i to r do for j to c do k := k+1; Lambda[i, j] := v[k] end do end do;
eval(Lambda);
end proc;

thanks a lot!...

Thanks! now it works as expected.

Harry

this is what I am trying to accomplish...

For some statistical software the user can give restrictions for the parameters. Here a mapping of a probability to zero and one (giving 0.5 the benefit of the doubt)

@Markiyan Hirnyk    This is wh...

This is what Axel wrote in 2008:

"For me the function x^a is not defined in (0,0) as a continous limit, so setting it to a value
would be ok and reading it as exp of limit(ln(x)*x,x=0) I do not have problems with 0^0=1 as
convention."

What does he mean: it is both undefined and by convention equal to 1?

Should maple give two answers? undefined and 1?

not in Maple T.A. unfortunately...

Indeed this works in Maple, but unfortunately not in Maple T.A.

It gives the following output:

1 3 \n1 3 \n2 5 \n0 5 \n2 4 \n2 2 \n2 3 \n2 3 \n2 3 \n2 3 \n2 2 \n2 4 \n2 4 \n2 3 \n2 2 \n1 2 \n2 2 \n3 3 \n1 4 \n1 2 \n1 5 \n3 2 \n2 4 \n1 3 \n2 4 \n2 3 \n3 3 \n1 3 \n1 5 \n2 3 \n3 2 \n4 3 \n2 2 \n2 3 \n2 5 \n4 4 \n3 2 \n1 2 \n2 3 \n3 2 \n1 2 \n1 4 \n1 5 \n1 4 \n1 2 \n3 3 \n2 4 \n1 3 \n4 3 \n1 3 \n2 2 \n2 4 \n1 3 \n2 4 \n2 4 \n3 3 \n3 3 \n2 3 \n3 3 \n1 5 \n2 4 \n2 3 \n0 1 \n1 3 \n1 4 \n1 5 \n1 1 \n4 1 \n1 3 \n4 4 \n0 3 \n1 3 \n2 3 \n2 4 \n4 4 \n2 4 \n3 4 \n2 4 \n3 2 \n1 4 \n3 2 \n1 2 \n1 2 \n3 3 \n3 3 \n1 3 \n1 4 \n2 5 \n1 2 \n4 3 \n1 4 \n3 3 \n2 3 \n2 5 \n2 4 \n4 4 \n1 3 \n1 2 \n4 3 \n3 4 \n

1 3

1 3

2 5 etc

Thanks anyway,

Harry

thanks!...

Thanks a lot! Now it works!

have a nice weekend!

Harry

syntax wrong??...

@Harry Garst

Thanks.  Although my incorrect syntax does what I aimed for outside a proc.

Unfortunately, your suggestion did not work in a proc:

restart;
Generate:=proc()
local MultivariateNormalSample,S,W,K,M,Z,i;
with(LinearAlgebra): with(MTM): with(StringTools):
MultivariateNormalSample := proc (Sigma, V, N) local d; d := LinearAlgebra:-Dimension(V); LinearAlgebra:-LUDecomposition(Matrix(Sigma, datatype = float[8]), 'method' = 'Cholesky') . ArrayTools:-Alias(Statistics:-Sample(Normal(0, 1), d*N), [d, N])+ArrayTools:-Replicate(Vector[column](V, datatype = float[8]), 1, N) end proc: S := MultivariateNormalSample(`<,>`(`<|>`(1, 2), `<|>`(2, 5)), `<,>`(2, 3), 100):
W := int8~(round~(S)): return W;
end proc;Generate();

What is going on?

Does it work on your computer?

Harry

still one problem to solve......

I decided to use StringTools. Now I have only one problem left: how to insert line feeds after each row of observations?

Here is the source code:

mode=Inline@
name=generate@
comment=@
editing=useHTML@
solution=@
algorithm=\$datastring1=maple("
with(LinearAlgebra):
MultivariateNormalSample := proc (Sigma, V, N) local d;
d := LinearAlgebra:-Dimension(V);
LinearAlgebra:-LUDecomposition(Matrix(Sigma, datatype = float[8]), 'method' = 'Cholesky') . ArrayTools:-Alias(Statistics:-Sample(Normal(0, 1), d*N), [d, N])+ArrayTools:-Replicate(Vector[column](V, datatype = float[8]), 1, N) end proc:
S := MultivariateNormalSample(`<,>`(`<|>`(1, 2), `<|>`(2, 5)), `<,>`(2, 3), 100):
with(MTM):
W:=int8~(round~(S)):
with(StringTools):
K:=convert(W,string):
K:=Drop(K,17):
K:=Select(IsDigit, K):
M := seq(PadRight(K[i], 2), i = 1 .. Length(K)):
Z:=M[1]:
for i from 2 to Length(K) do: Z := cat(Z, M[i]): end do:
Z;
");
\$datastring=[\$datastring1];@
uid=c3067c18-5859-4aa8-9cbb-23fbbb8da3f8@
weighting=1@
numbering=alpha@
part.1.name=sro_id_1@
part.1.numStyle= @
part.1.editing=useHTML@
part.1.showUnits=false@
part.1.question=(Unset)@
part.1.mode=Numeric@
part.1.negStyle=both@

I would like to use two strategies: firs...

I would like to use two strategies:

first, offer the students a simple tab delimited data file.

second, to circumvent browser incompabilities I would like to display the data before the questions section starts.

Therefore, I need the rectangular free format

1 2

3 4.

If the first method fails a student can select the data from the web page and copy an paste the data in a syntax file.

Otherwise, there will be always a student who complains that he cannot download the data.

Harry

@Markiyan Hirnyk    The purpos...

The purpose is to be able to to offer a plain text file with data as a download for students who follow a statistical course.

The students have to learn how to use statistical software (SPSS) for analysing their data.

Because many, many maple commands simply do not work in Maple T.A. I cannot use straightforward commands like ExportMatrix or writedata etc.

Also the whole library URL and HTTP do not seem to work in the Maple T.A. environment.

Fortunately, after several month I found I could use the following code:

here the complete sourcecode:

name=export data.txt@
comment=@
editing=useHTML@
solution=@
algorithm=\$datastring="1 2 3 4 5";@
uid=879b593f-0357-4a07-9420-66416ccf50db@
weighting=1@
numbering=alpha@
part.1.name=sro_id_1@
part.1.numStyle= @
part.1.editing=useHTML@
part.1.showUnits=false@
part.1.question=(Unset)@
part.1.mode=Numeric@
part.1.negStyle=both@

The problem I'm facing now is how to format \$datastring as a tab delimited data file (with observations for a single observation unit on a single line):

1 2

3 4

This is what I have now in the algorithm section:

\$R=maple("
with(LinearAlgebra):
MultivariateNormalSample := proc (Sigma, V, N) local d;
d := LinearAlgebra:-Dimension(V);
LinearAlgebra:-LUDecomposition(Matrix(Sigma, datatype = float[8]), 'method' = 'Cholesky') . ArrayTools:-Alias(Statistics:-Sample(Normal(0, 1), d*N), [d, N])+ArrayTools:-Replicate(Vector[column](V, datatype = float[8]), 1, N) end proc:
S := MultivariateNormalSample(`<,>`(`<|>`(1, 2), `<|>`(2, 5)), `<,>`(2, 3), 100):
with(MTM):
W:=int8~(round~(S)):
with(StringTools):
K:=convert(W,string):
K:=Drop(K,17);
");

with gives as output:

K := "1,1,2,0,2,2,2,2,2,2,2,2,2,2,2,1,2,3,1,1,1,3,2,1,2,2,3,1,1,2,3,4,2,2,2,4,3,1,2,3,1,1,1,1,1,3,2,1,4,1,2,2,1,2,2,3,3,2,3,1,2,2,0,1,1,1,1,4,1,4,0,1,2,2,4,2,3,2,3,-1,3,1,1,3,3,1,1,2,1,4,1,3,2,2,2,4,1,1,4,3],[1,2,5,1,4,2,3,3,3,3,3,3,5,3,1,-1,3,4,3,0,2,5,5,0,4,3,4,1,4,2,4,7,3,3,5,8,4,0,2,3,0,2,2,3,1,5,3,1,6,2,3,4,1,4,3,5,5,2,4,4,4,3,-2,0,2,2,-1,4,1,8,-2,1,3,5,8,4,5,4,4,-1,3,1,1,5,4,1,2,5,-1,6,2,4,3,4,3,8,2,1,6,5]])"

I tried using StringTools SubstituteAll to get rid off the non digit characters ]], but SubstituteAll gives an error.

Another attempt was adding the following line:

Select(IsDigit, K);

but then I have to find a way to insert blanks and line feeds.

My purpose is to create an object \$datastring as a text string including line feeds.

As many universities offer statistical courses using SPSS I believe my question is more than a personal matter.

the following commands do not work in Ma...

the following commands do not work in Maple T.A.

printf("%{c }a\n", A);

The following error message was generated: The character % cannot be used in a formula

writedata(terminal, convert(A, matrix), string);

java.io.IOException: Maple computation error

Many other commands do also not work in  Maple T.A.

@Markiyan Hirnyk    sorry, ind...

sorry, indeed I interpreted FAIL as FALSE.

But indeed 'simplify' does the trick, although I do not understand why.

restart; assume(x, 'real');
verify(abs(x), sqrt(x^2), {'equal'});
FAIL
verify(abs(x), simplify(sqrt(x^2)), {'equal'});
true
is(abs(x) = sqrt(x^2));
FAIL
is(abs(x) = simplify(sqrt(x^2)));
true