MaplePrimes Questions

Let E be a random variable of expectation mu and A an algebraic expression containing no random variable.
If E has any known Maple distribution, then  Mean(A+E) = A+mu.

But if E is an "abstract" random variable, Mean doesn't seem capable to compute the expectation of A+E.
Notional example:

restart:
with(Statistics):
E := RandomVariable(Normal(mu, sigma)):
Mean(f(x)+E)
                           f(x) + mu
E := RandomVariable(Distribution(PDF = (z -> f(z)), Mean=mu)):
Mean(f(x)+E); 
     int((f(x) + _t) f(_t), _t = -infinity .. infinity)

IntegrationTools:-Expand(%);
        f(x) (int(f(_t), _t = -infinity .. infinity)) + (int(f(_t) _t, _t = -infinity .. infinity))

Questions:

  • Why does Mean not behave as expected for an abstract random variable?
  • Is there a simple way to obtain the expected result (Mean (A+E) = A+mu) (maybe by completing the definition of the distribution of E, or by any other means)?

TIA

PS: I know that I can replace Mean(A+E)  by A+Mean(E)  to obtain the desired result: this is not the type of answer I look for.

PS: I know (since Carl Love showed me how long ago) that I can define a "random variable" plus an operator Expectation such that Expectation(A+E)  by A+Expectation(E) ... but it's not a way I would call simple

Expectation := proc(e::algebraic)
     local a,b;
     if not hastype(e, RV) then e
     elif e::RV then 'procname'(e)
     elif e::`+` then map(thisproc, e)
     elif e::`*` then
          (a,b):= selectremove(hastype, e, RV);
          b*thisproc(a)
     else 'procname'(e)
     end if
end proc:

#------------------------------------------------------------------------

TypeTools:-AddType(
     RV, 
     {RandomVariable, 
     'RandomVariable^posint', 
     '`*`'({RandomVariable, 'RandomVariable^posint'})
     }
):
eval(Expectation(f(x)+E), Expectation=Mean)
                           f(x) + mu

 


 

13.5.2021

 

 

 

 

   

``

 

 

 

 

NULL

NULL

NULL

`&*` := proc (A := 1, B := 4, b := 2, d := 4) local c, i, k; c := 0; [seq(irem(c+add(A[i]*B[k+1-i], i = 1 .. k), b, 'c'), k = 1 .. d)] end proc

NULL

NULL

NULL

`&*`()

[irem(1[1]*4[1], 2, c), irem(1[1]*4[2]+1[2]*4[1], 2, c), irem(1[1]*4[3]+1[2]*4[2]+1[3]*4[1], 2, c), irem(1[1]*4[4]+1[2]*4[3]+1[3]*4[2]+1[4]*4[1], 2, c)]

(1)

NULL

NULL


 

Download mod_proc.mw

Hi 😊

I have found this Code here somewhere in MaplePrimes.

I am very interested in that Procedure, but it doesn't run.

I will be very happy, to get help with that.

Thanks a lot,

Arno

 

 

Hello

 

When doing chemistry in Maple, I want to be able to do my calculations with units.

Maple does not support the unit [M] (molar concentration), so I have to manually type the unit as [mol/L].

 

That is not a problem in itself, but I have encountered som issues with Maple's own formatting of the units.

For example, in the attached document I want the output unit to be (mol/L)^(-2). However, Maple automatically formats it as (L^2)/(mol^2)

It even does the same thing in the "Maple Math" here on MaplePrimes - Here I try to type (mol/L)^(-2): (mol/L)^(-2)

 

So does anyone know a way to avoid Maple's auto-formatting of the output, or is there a way to customize it so I get my desired output?

 

I have attached the document with some screenshots in it: chemistry_units.mw

 

// Frederik

primes.mw

As a result of a calculation I have a long expression. I give it a name, say, X,

X:= long expression. 

I try to use typematch to extract different parts of X and its does not work (it returns false).  

If, however, I copy and paste the long expression from the output and plug into my typematch query it works!   

It seems that copy and paste change the type of the expression. I am very confused with this. 

 

I have uploaded a file with the problem at the beggining.  Thank you! 
Max 
 

 

Hey guys, how can I apply multiplication to a sequence of matrices like A[1], A[2]...A[n] so it becomes A[1]*A[2]...*A[n] ? thanks in advance

I am investigating the history of scales and temperament in western music. I would like to be able to play a tone of a given frequency in Maple, and then a sequence of tones to make a scale, and then a collection of tones to make a chord. I found the Play command  in the online help screen for Audio Tools, but can't make it work. I don't get an error message, but neither do I get a sound. 

Hi,

exploring this package for a graduate course (to physicists, actually).

When calculating diatomic potential energy curves for Ar-F (using Parametric2RDM, or CC) I am running into trouble,

a discontinuity appears at about R=3 Angstroms.

This happens for many wavefunction sets (cc-pVXZ with X=D,T,Q,5, also augmented set on F)

The problem might be basis set superposition error (BSSE), treated usually by counterpoise, i.e., doing the monomer calculations with the molecular basis, by putting in ghost basis for the other atom at the given distance R.

I couldn't figure out whether, in fact, the package supports some treatment at this level, and/or if it does, how to implement it.

many thanks

marko

I am merging two separate modules  B,C to be child modules inside one main A module.

Now, I found the code breaks, because uses does not work any more.

Before merging, C module did uses B. But now this gives an error when both B,C sit inside one parent module.  An example make this easier to explain

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

A:=module()

   export B:=module()
     export foo:=proc()
         print("In B:-foo()");
     end proc;
   end module;

   export C:=module()
      uses B; #this cases problem
      export boo:=proc()
           foo();
      end proc;
   end module;
end module;

Error, (in A:-C) no bindings were specified or implied

Changing uses B; to uses A:-B; does not help. I get error Error, (in A:-C) `A` does not evaluate to a module

I also tried uses :-A:-B; , now this does not give error, but it does not work. i.e. when doing  A:-C:-boo() Maple does not end up calling foo() inside module B as expected.

One way to avoid all this, is not to use uses B inside the module and do this instead

A:=module()

   export B:=module()
     export foo:=proc()
         print("In B:-foo()");
     end proc;
   end module;

   export C:=module()      
      export boo:=proc()
           B:-foo(); 
      end proc;
   end module;
end module;

But it means I have to now change lots of code inside the C module, and add an explicit B:- everywhere

This is how it was before the merging

B:=module()
   export foo:=proc()
       print("In B:-foo()");
   end proc;
end module;

C:=module()  
  uses B;    #no problem now
  export boo:=proc()
      foo();  #this now uses B:-foo() automatically due to uses.
  end proc;
end module;

The above works. Now I can do C:-boo() and it works as expected.

The question is: How to make it work after moving both C and B inside one parent module so I do not have to change lots of code? I tried many things, but can't get it to work.

Maple 2021 on windows 10

Edit

Thanks for the answers below. I think I have to change my code then either way to add a prefix to the call. I actually always use the long form of the call for everything as in module:-function() but for one function, which I use so much everywhere, using the fully qualified name would make things hard to read.  This function converts Maple expressions to Latex after some filtering. Here is an example

cat(",toX(y),"' = f_0(",toX(f),")",toX(y),"+f_1(",toX(x),")",toX(g),"^n \\tag{2}, etc.....")

Now the function toX comes from one module, the one I had uses for it. Now I have to change the above to becomes

",module_name:-toX(f),"' = f_0(",module_name:-toX(x),")",module_name:-toX(y),"+f_1(",module_name:-toX(x),")",module_name:-toX(g),"^n \\tag{2}

Since my strings are very long as it is, (program generates Latex on the fly as it runs), this will make them even longer and harder to read.

But I can change all this in the editor, using global search and replace.

I was just hoping I do not have to just because I moved the modules all into one main module. I still do not understand why Maple does not allow uses when moving the modules inside one bigger module, but I guess this is by design.

Hello

I have a couple of large lists that will be further processed.  One of the steps is to index a list using another list (a list of indices).  A short example will be something like

L:=[2,1,4,3,7,6,8,3,4,5];
ind:=[2,2,3,3,5,6,7,1,4,10];

The solution 

L1:=L[ind]:

does not seem to be a good choice since it takes longer than the following solution

 

L1:=Threads:-Map(w->L[w],ind):

 

Since I am not a Maple expert, it is very likely that is a faster solution.   

 

Many thanks

 

Occasionally commands in the form of (exprseq1)(exprseq1) are proposed.

(as the solution in https://www.mapleprimes.com/questions/232263-Subscripts-In-Maple)

Questions:

  • Is this syntax and its use documented somewhere?
  • Can the first parenthesis (exprseq1) be considered as an operator?
  • In which situations such commands are preferable?

I had look at Maples help system but could not find any further explanations. What I found so far:
syntax talks about parenthesized expression and refers to
operators,precedence which does not define the precedence of parenthesis
examples,functional two examples show the use of functional operators within rounded brackets
help("Definition,bracket") explains the different types of brackets [moderator note: in common mathematical parlance, not in the technical sense in Maple].

ProgrammingGuide,Chapter02 only refers to a pair of rounded brackets but not 2 pairs
The left and right parentheses group terms in an expression, arguments in a function call, and parameters in a procedure definition.

...

The left and right parentheses are also used to select components from certain data structures (programmer indexing).

Hi, I have created a procedure and it keeps giving the error "Error, reserved word `then` unexpected". What am I doing wrong?


Clasterms:=proc(P)
local L,a,b;
L:=(`[]`@ op)~(indets(P, indexed));
a:=Search(1,L[1]); b:=Search(2,L[1]);
 if a<>0 and b<>0 then print("mixed");
 elif a<>0 and b=0 then print("t-only");
 elif a=0 and b<> then print("x-only") ; end if;
 end proc:

Product: Maple 2021

hey guys, I'm curious if there is any way to do a group assignment like the following

JointNum := 3;
                    
seq(alpha[i], i = 1 .. JointNum) := 0, 0, 0;

which should as result be the following assignment

alpha[1], alpha[2], alpha[3]:=0,0,0

which is a valid assignment standalone but not works in the sequence style form . how can I implement this type of assignment

When trying to understand what a proof is trying to show, I like to construct some examples to see what the proof is trying to show. For example, constructing some sequence to show whether it converges, visualizing some functions to understand the squeeze theorem in calculus, etc. I found Maple has worked well for this kind of work.

Now I am taking course in Measure Theory and everything is so abstract and I am not sure if Maple is capable of building the objects discussed. For example, this is from the book Probability Essentials:

How can I use Maple to support understanding the proofs? It would be nice if I can build the objects discussed and write functions to verify their properties and just play around with them in general to get an intuition of how the proof works.

 

 

 

 

Hi, when I tried the simple example of Java OpenMaple on Mac, I can compile the code but couldn't run it. It complained about not finding libjopenmaple.jnilib. I checked that library directory, there was /libjopenmaple.jnilib but not libmaplec.dylib. Any suggestions?

> java -Djava.library.path=/Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX -classpath "$MAPLE/java/externalcall.jar:$MAPLE/java/Maple.jar:." test

Error loading libraries: java.lang.UnsatisfiedLinkError: /Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib: dlopen(/Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib, 1): Library not loaded: @rpath/libmaplec.dylib
  Referenced from: /Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib
  Reason: image not found
java.lang.UnsatisfiedLinkError: /Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib: dlopen(/Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib, 1): Library not loaded: @rpath/libmaplec.dylib
  Referenced from: /Library/Frameworks/Maple.framework/Versions/2021/bin.APPLE_UNIVERSAL_OSX/libjopenmaple.jnilib
  Reason: image not found
    at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
    at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:383)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:227)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:169)
    at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:316)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:282)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2440)
    at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:809)
    at java.base/java.lang.System.loadLibrary(System.java:1893)
    at com.maplesoft.openmaple.Engine.<clinit>(Engine.java:23)
    at test.main(test.java:22)
Exception in thread "main" java.lang.UnsatisfiedLinkError: 'long com.maplesoft.openmaple.Engine.getKernel(java.lang.String[], com.maplesoft.openmaple.EngineCallBacks, java.lang.Object, java.lang.Object)'
    at com.maplesoft.openmaple.Engine.getKernel(Native Method)
    at com.maplesoft.openmaple.Engine.<init>(Engine.java:44)
    at test.main(test.java:22)

 

 

Dear Community,

I try to slove a simple 2nd order ODE describing a simple pulley. Unfortunately dsolve does not like what I'm trying to do, and I get en error message. My goal is to plot travel distance, velocity and acceleration (  h(t), dh(t)/dt, d2h(t)/dt2 ) of the lifted weight. Could you pls. have a look what I'm doing wrong?

Also is there a way to transform this worksheet to a MapleSim document somehow? Worksheet attached.

tx in advance,

best regards

Andras

SimplePulley.mw

 

First 285 286 287 288 289 290 291 Last Page 287 of 2308