mmcdara

7891 Reputation

22 Badges

9 years, 63 days

MaplePrimes Activity


These are replies submitted by mmcdara

@Carl Love 

Thanks Carl

@Carl Love 

A question by the way: why writeto(SomeFile) doesn't redirect the output of showstat to SomeFile?
It looks like the "output" of showstat is not a "true" output?

@Carl Love 

Great, I vote up

@acer 

I didn't know about this %P option of printf.
It is a very interesting option.

I can't resist the pleasure of showing you how I've managed so far to do the same job that Pascal4QM wanted to do:

  1. Let F.mw the worksheet which contains the procedure f and the showstat(f) command.
  2. Export F.mw in a mpl file named F.mpl
  3. In a terminal window run the command    maple F.mpl >> F.txt
  4. Read F.txt in a Maple worksheet and extract the informations generated by showstat while discarding the line numbers

 

Here is an example:

  • F.mw contains your procedure f
  • readF.mw  "extracts" the desired informations from F.txt

Download F.mw

Download readF.mw

restart

/Library/Frameworks/Maple.framework/Versions/2015/bin/maple   /..../F.mpl  >>  /..../F.txt

 

inputfile := cat(currentdir(), "/Desktop/F.txt"):
line := readline(inputfile):

FirstCommandFound := false:
WithinProcedure   := false:
EndOfProcedure    := false:
while `not`(EndOfProcedure) do
   line := readline(inputfile):
   if substring(line, 1..1) = ">" then FirstCommandFound := true end if;
   if substring(line, 1..1) <> ">" and FirstCommandFound then
     if substring(line, 1..1) <> " "  then
       printf("%s\n", line);
       EndOfProcedure := copy(WithinProcedure):
     else
       printf("%s\n", cat("       ", substring(line, 8..-1)));
       WithinProcedure := true:
     end if:
   end if;
end do:


f := proc(x)
       if x <= 2 then
         if 0 < x then
           print(-x)
         else
           print(-x^2)
         end if
       else
         if 0 < x then
           print(-x)
         end if
       end if;
       print(-x);
       x^3;
       if x <= 2 then
         if 0 < x then
           if -5 < x then
             print(-x)
           end if
         else
           print(-x^2)
         end if
       else
         if 0 < x then
           if -5 < x then
             print(-x)
           end if
         end if
       end if
end proc

 

 


It's complicated and requires manual actions.
The only advantage, if any, compared to the %P option is that one gets exactly the same output showstat produces (minus line numbering)

@vv 

Thanks vv,
Your answer matches Acer's on the need to save the module associated to the 3rd attribute.
Meanwhile I fixed the problem by saving the laws and their parameters for each RV and rebuilding them after reading the file?
 

@acer 
Thanks for your detailed answer.

You wrote "So I would suggest that instead you store whatever is needed to create the RVs afresh...": this is indeed what I did as I was waiting for a reply (saving the laws and the parameters for each RV, reading the file and generating the RV from the read material).


 

No answers, just additional comments

I just load the link to the mw file because the plots displayed when I "insert contents" do not present the spurious horizontal segments.
Which means the problem you (and I) observe in a Maple worksheet probably comes from an interaction between the screen and the plot engine.

PS: plotting the circle with options style=point, symbol=point  works well too.

Download partial.mw

@Joe Riel @Carl Love

Forget it.
Thank you for your involvement

@Joe Riel @Carl Love

Thank you Joel. 
Maybe this could help me a lot, but I understand this package is neither updated neither avaliable, am I right?

In order to let you judge if it could suit me I 'm going to describre briefly the reason of my question (this will enlighten Carl too)

I have developed an application whose some part is aimed to assess the drag force a fluid develops on a moving piece immersed in it. This drag force depends on the (2D) geometry of the fluid domain and of the fluid properties.
I have written a graphical interface (maplets) to ease the users to introduce the data.  One such data can be, for instance, the radius R of an orifice the fluid passes through.

The geometry is defined by a set of lists of points named [A1,..Am], [B1, ..., Bn] and so on. The user can declare this radius R (textfield component) by giving a numerical value or the name of the point which references this radius.  Sometimes it is also useful to define this radius by a formula.

Once the "value" of R given, I treat it in a way with depends on its type (is it a numerical value, a symbol, an algebraic expression...?). I've written a procedure where embedded 'if' structures separate the diferent situations, but it's not always easy to find the "good type" which distinguishes two different representations of this same radius R.
I've spent a lot of time groping around to develop this procedure, and in some cases, it still can fail.

Now, suppose I have a procedure that returns all types of an object A and an object B, it would be the easiest thing in the world to find out which types discriminate A and B

@Carl Love 

Hi,

Yes, I know about the difference between with an uses: I guess I wrote with(..) the block afer the restart ant then accidentally displaced it within the body of the procedure.

About Answers and Replies... could you explain clearly what difference you make between the twos (in french the both translate into the same word). You already said me something like  "an answer is the definitive and unique answer to a question while a reply is just one among many proposals to answer this problem". Is this right?
With this in mind what I wanted to send was a reply, not an answer: if I sent an answer, please consider it as a mistake on my part and not as a deliberate act.

PS: copy-paste your phrase "Please stop posting things that should be considered Answers as Replies." into DeepL, translate it to french, take the result and translate it ot english in order to understand the ambiguity between answer and reply.
Maybe the term reply could be appropriately replaced by proposal?
 

@acer 

Thanks for this quick reply.

I'm going to see what I can do with this idea of acting "inplace" (even if I only used this as an option for some matrix manipulation and if I'm not sure to really understand how to proceed here).
I understand you're maybe going away for the weekend? If it so, have a good weekend, I will continue on my side to work a little in the directions you suggested.

Thanks

Here is a more realistic code Not_Efficient_detailed.mw
(the "model" I use inside is a toy model, in true applications its the output procedure returned by dsolve parameterized by P parameters)

 

 

 

@tomleslie 

Thanks for the answer but I think I didn't set the things clearly enough.
So let me formalize the problem in another way.
I have a procedure P which realizes different operations. Let's say its strucure is this one:

P := proc(K)
... some operations
for k from 1 to K do
   build the NxP random matrix X (an illustration if given in my previous question through procedure f1)
   realize some operation on X
end do
... some operations
return some result 
end do:

Let S the size of object Z and assume the memeory size require by all the operations but the construction of X are much smaller than S.
Than the "memory cost" of procedure K is of order K*S.

In Fortran (for instance, but I could also have taken C++ as an other example) I know how to assign a part of the memory to symbol X in order that each of the K constructions of X are written at this same memory place (which would result in a "memory cost" of P equal to S).
I don't know how to mimic the same thing in Maple.

A notional example is given here Not_Efficient_2.mw
Two different strategies are used: each of them has a cost equal to N*S. My question is: "How should I write the main procedure and declare X in order that its global cost might be S and not N*S?"

Hope I'm clearer?

TIA

@tomleslie 

Why do you say "the former is a piecewise continuous distribution, whereas the the latter is discrete"

The attached file contains an example that proves both EmpiricalDistribution and ProbabilityTable are discrete random variables. Here is the argument

  • Only discrete RVs have the attribute "ProbabilityFunction" 
  • While only continuous RVs have the attribute "PDF".

Your argument concerning the evaluation of X and Y at point "2.5" is not good: or more exactly it could be ... if Maple treated correctly discrete random variables, which it doesn't (I already posted a lot of remarks about this).
To convince you just run this simple example 
U := RandomVariable(DiscreteUniform(1, 3)):
ProbabilityFunction(U, 1.5)



(sorry I've always this f... error)
Maple Worksheet - Error
Failed to load the worksheet /maplenet/convert/Discrete_vs_Continuous.mw .

Download Discrete_vs_Continuous.mw

@Carl Love 

I was about to complete my reply by saying the same thing.
My first proposal is not safe ("abc" and "acb" have the same number of bytes); yours is safer but can be lure if you have use the Linux command "touch" meanwhile.
The safest thing is probably system("diff oldfile newfile") (Linux or Mac OSX, I'm not sure diff is a command for Windows) but it requires a systematic copy of the file before any possible change

I don't know exactly what you want to do, so don't take this answer as an end, but simply as a sharing of experience.

I use to call R from Maple in order to delegate some specific computations to R. Once done Maple takes back the hand and keeps going on.
To do this I use the procedure system (or ssystem, see help pages)  under the form system(cmd) where cmd is a string which contains the command to run (for instance cmd := "//.../exec inputfile"
Here "exec" is the name of the executable to run (geogebra.exe in your case) and inputfile is a file that contains the set of command "exec" must execute.
As I know the syntax of R, I write this inputfile directly from Maple (inputfile is a text file). If you are familiar with the inline mode of Geogebra you could probably do the same.
For instance if inputfile must contain y=x+1, you could do

  • fd := fopen(inputfile,WRITE, TEXT);
  • execute fprintf(fd, "y=x+1\n")
  • close(fd)
  • cmd := "//.../exec inputfile"
  • system(cmd)

You should stay in the Geogebra environment until you quit it, which will "close" the system command and set you back in your Maple worksheet

As a rule the last command in inputfile is aimed to write the results of the computations R has done in some file. Once the procedure system executed, Maple just reads this file.

I don't know if it's been helpful to you

First 110 111 112 113 114 115 116 Last Page 112 of 154