Anthrazit

415 Reputation

8 Badges

2 years, 81 days

MaplePrimes Activity


These are replies submitted by Anthrazit

Looks like this is the way it should be.

If I want a text description, it needs to be put in the attribute list, not the name of the XML element to create.

@TechnicalSupport 

I've made it a habit to copy files to the local PC, especially when working via VPN.

Haven't had any problems afterward either.

So for the moment it's not reproduceable anymore.

As far as I remember there was neither a file called "C" nor a attachment with the name "C". So the error message must have come from somewhere else.

@Carl Love 

Thanks a lot for your patience.

I've done some more tests, and as you write in your last comment, the problem is the parse instruction, not the table that is returned.

Looks like this is a reoccurring problem on my side.

https://www.mapleprimes.com/questions/232660-Local-Vs-Global-Variables-

In my opinion using declared globals in a procedure is generally a poor programming practice. Using parse to turn strings into names -- within a procedure -- is also generally poor a programming practice.

@Joe Riel 

I think the attached example resembles very much your second example, where all variables are declared local.

But the question is, how do I fix the code so that I get back the values, and not the name of the variables?


 

NULL

test := proc()

 

result := test()

atable

(1)

result["a"]

a

(2)

NULL


 

Download table_test.mw

@acer 

Apparently not :-)

I've tested all of the programs I wrote recently to use the Units:-Simple package, and all but one ran without any problems.

The one that didn't run properly had a problem during units conversion. But actually that was a bug in my program. It might be that the Units:-Simple package actually helped finding the bug, while the Standard package justed worked on. But I am not sure on that either.

So it looks like that I will change to the Units:-Simple package from now on.

"with(Units[Simple]);"

[`*`, `+`, `-`, `/`, `<`, `<=`, `<>`, `=`, Im, Re, `^`, abs, add, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctanh, argument, ceil, collect, combine, conjugate, cos, cosh, cot, coth, csc, csch, csgn, diff, eval, evalc, evalr, exp, expand, factor, floor, frac, frem, ln, log, log10, log2, max, min, mul, normal, piecewise, polar, root, round, sec, sech, seq, shake, signum, simplify, sin, sinh, sqrt, surd, tan, tanh, trunc, type, verify]

(1)

a := 15*Unit('kN')

15*Units:-Unit(kN)

(2)

b := 0*Unit('kN')

0

(3)

NULLNULL

if a < b then "True" else "False" end if

"False"

(4)

NULL

Download CompareUnits_(1).mw

@Ronan 

No, didn't try that one.

@vv 

But why doesn't it come with an error exception then?

If I do sin(2,3,4) I'll get an Error, (in sin), expecting 1 argument, got 3.

The equivalent function for degrees seems to give different results, and I don't understand what it does actually.

with(Degrees)

[ConvertToDegreeForm, ConvertToRadForm, HasTrig, SetDefault, Simplify, arccosd, arccotd, arccscd, arcsecd, arcsind, arctand, cosd, cotd, cscd, diff, expand, int, secd, sind, solve, tand, trigsubs]

(1)

arctan(1, 0)NULL

(1/2)*Pi

(2)

arctand(1, 0)

45

(3)

arctan(0, 1)

0

(4)

arctand(0, 1)

0

(5)

arctan(0, -1)

Pi

(6)

arctand(0, -1)

0

(7)

NULL

Download arctan.mw

@Ronan 

That seems to me 2 different questions now.

The one important to me is why the < operator doesn't work with the Units-Standard package. That is the most important one to fix.

The other one is the question about the workaround with "is". That one apparently doesn't give the desired results either, so for my part this isn't a path I am going to follow further on.

The intermediate solution is to change all my if clauses, and convert the values that should be checked to unit_less ones, before doing the calculations. Needless to say that the main reason for implementing the check in the first run is that Maple often exits with an error if units get lost.

The main problem for all this behaviour is, that Maple cuts out units when a value becomes zero. This is a bug in my opinion, and as I have posted before, other software like Mathcad does not show this behaviour.

@Ronan 

The last line should give "True" not "False".


 

with(Units[Standard])

[`*`, `+`, `-`, `/`, `<`, `<=`, `<>`, `=`, Im, Re, `^`, abs, add, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctanh, argument, ceil, collect, combine, conjugate, cos, cosh, cot, coth, csc, csch, csgn, diff, eval, evalc, evalr, exp, expand, factor, floor, frac, int, ln, log, log10, log2, max, min, mul, normal, polar, root, round, sec, sech, seq, shake, signum, simplify, sin, sinh, sqrt, surd, tan, tanh, trunc, type, verify]

(1)

a := 15*Unit('kN')

15*Units:-Unit(kN)

(2)

b := 0*Unit('kN')

0

(3)

NULLNULL

if a < b then "True" else "False" end if

Error, cannot determine if this expression is true or false: 15*Units:-Unit(kN) < 0

 

NULL

if is(a < b) then "True" else "False" end if

"False"

(4)

NULL

if is(a <> b) then "True" else "False" end if

"False"

(5)

NULL


 

Download CompareUnits.mw

@Ronan 

This is indeed an interesting approach that seems to work.

@Thomas Richard 

The Simple package doesn't allow for unit conversions and a lot of other stuff, so we need Standard package.

@acer 

Looks like you are right.

The problem was that there is an argument switch between Excel and Maple.

Excel arctan2(x, y), while Maple arctan(y, x).

arctan(1, 0)``

(1/2)*Pi

(1)

arctan(-1, 0)

-(1/2)*Pi

(2)

arctan(0, 1)

0

(3)

``

arctan(0, -1)

Pi

(4)

NULL


 

Download arctan.mw

@acer 

Thanks a lot again. I did understand my original mistake in your first explanation already.

The crucial thing is to understand, when something gets evaluated. And I still think that is not always clear.

  • "When entries of a Vector are accessed individually they get evaluated."
    Nice, but where do I find this information?
     
  • This following entry in Maple Help (look for "eval) is also a bit tricky to understand:
    "Applying eval to mutable container objects like tables, rtables, and modules does not map over the elements.  Use map(eval,M) to evaluate elements in an object, M."

    Does "map over" mean the same as thing we are talking about here?

 

@acer

Thanks a lot, that was very helpful.

But one more question, as I need to understand when an object is mutable, and when it isn't anymore.

I've used one of your examples in the following code, and added something to the end. When do the values in that code become unmutable? A change of the values of aVectorList don't have any consequences to the resultlist.


 

restart; aVectorList := [Vector(2, [1, 2]), Vector(2, [3, 2])]

[Vector[column](%id = 36893490930679169140), Vector[column](%id = 36893490930679169260)]

(1)

" results:=Array():  AddVector:=Vector(4): for i from 1 to nops(aVectorList) do     AddVector:=Vector(4):     AddVector[1] := aVectorList[i][1];     AddVector[2] := aVectorList[i][2];     results(i):= AddVector; end do: resultlist:=convert(results,list);"

[Vector[column](%id = 36893490930679162868), Vector[column](%id = 36893490930679163108)]

(2)

aVectorList[1] := Vector(2, [4, 5])

[Vector[column](%id = 36893490930679159012), Vector[column](%id = 36893490930679169260)]

(3)

resultlist

[Vector[column](%id = 36893490930679162868), Vector[column](%id = 36893490930679163108)]

(4)

NULL


 

Download Mutable1.mw

1 2 3 4 5 6 7 Last Page 1 of 11