Harry Garst

269 Reputation

6 Badges

19 years, 145 days

MaplePrimes Activity


These are replies submitted by Harry Garst

the first and the second example are completely the same (except for the indices [1,1] versus [2,1].

I made a new maple file. The second example is a copied version of the first example, but the indices are changed. The output differs.

mapleprimes2.mw

@Preben Alsholm 

Thanks for diving in this issue.

Now it is time for the maple software engineer who wrote the 'forget' function (error message: Error, (in forget) lexically scoped parameter out of context). Strange name for a function. 

best regards,

Harry Garst

error_message.mw

no_error_message.mw 

 

sorry, I hoped it was something obvious I missed from my part.

In the meantime, I switched to the Optimization package, where I did not encounter any problems.

but, I still am curious why that error occurred.

kind regards,

Harry Garst

@Preben Alsholm 

 

Thanks! You are right!

kind regards,

Harrry

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 your reply. 

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
Lambda[row, 1] := Text[ReadNextFloat](file1)
end do;
Lambda;

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

old code:

Lambdaread:=proc(Lambda::Matrix,B)

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;

@acer 

 

Thanks! now it works as expected.

 

Harry

@acer 

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 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?

@acer 

 

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

 

instead of

1 3

1 3

2 5 etc

Thanks anyway,

Harry

@Harry Garst 

 

Thanks a lot! Now it works!

have a nice weekend!

 

Harry

@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

@Harry Garst 

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.answer.units=@
part.1.numStyle= @
part.1.editing=useHTML@
part.1.showUnits=false@
part.1.question=(Unset)@
part.1.mode=Numeric@
part.1.grading=exact_value@
part.1.negStyle=both@
part.1.answer.num=2@
question=<p>&nbsp;</p><p>&nbsp;</p><p><1></p><p>&nbsp; $datastring</p><p><a download="dataset.txt" href="data:text/plain;charset=utf-8,$datastring">download</a></p><p>&nbsp;</p><p>&nbsp;</p>@

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

 

1 2 3 4 Page 3 of 4