Mac Dude

1002 Reputation

13 Badges

6 years, 82 days

MaplePrimes Activity


These are answers submitted by Mac Dude

It has been like this since I started using Maple.

The work-around is to "Select all" (Cmd-a on macOS) and then hit the single-step button (!) to run the whole 2nd sheet.

I forget whether Maple will open a new worksheet when another one is running. You may need to open the 2n done first.

M.D.

 

You can work around the first problem by initially asking for the expansion to 6th order. After that everything appears to work fine; even when the forget(series) statement is removed.

I am not sure about the 2nd issue. The series command makes little sense as it only expands the linear term (x)... what is the point? You are still left with a transcendental equation that has no analytic solution. Maple 2015 hangs on the 2nd try to solve ser for y. Maybe you want expansion by y??

M.D.

 

 

e1:=0=(1-p)*π+φ*V+δ*R-(μ+λ+ϑ)*S;

e2:=0=p*π+ϑ*S-(μ+ϵ*λ+φ)*V;

e3:=0=ρ*λ*S+ρ*ϵ*λ*V+(1-q)*η*i-(μ+β+χ)*C;

e4:=0=(1-ρ)*λ*S+(1-ρ)*ϵ*λ*V+χ*C-(μ+α+η)*i;

e5:=0=β*C+q*η*i-(μ+δ)*R;

solve([e1,e2,e3,e4,e5],[S,V,C,R,i]);

The result is too messy to print here, see the worksheet. Do note that I is Maple's imaginary unit so I changed I to i.

M.D.

mprimes.mw

It depends on the specifics of your data and what you are trying to achieve. Technically, your Fourier analysis constitutes the test of a hypothesis, the hypothesis being that your samples are taken from a distribution given by your function, the Fourier series. If x could never be negative for fundamental reasons then I'd argue both Fourier series are equally valid; your data cannot discriminate between the two. The catch is that it is hard to imagine a case where x is fundamentally positive and a Fourier series is a valid representation of what is going on. When frequency analysis is meaningful, the independent variable (x) usually is a location or a time variable that is unbound in either direction.

What you really should do is have a model of the underlying distribution, i.e. of the process that generated the data in the first place. If that is symmetric about 0 then you are in a good place and can use the symmetry.

If you need to known the spectral composition of the Fourier series then you need to tread carefully here. Your two series have a significantly different spectrum; if you do not have enough data to discriminate between the two you may not be able to determine the spectrum of the underlying distribution.

M.D.

About the simplest way is to use the element-wise operations:

B:=sqrt~(1/~A); # note the tildes

More flexible is map(sqrt,A) which maps the sqrt function over all elements of A. RTFM for these. While map and ~ seem to be the same there are somewhat subtle differences, but for this simple case they should produce the same answer.

If the 0 elements in A bother you you can define a new  function

f:=x -> `if`(x>0,sqrt(1/x),0);

and use f~.

Mac Dude

Edit: Ninja'd by Rouben. I like Rouben's way of using an unnamed function...

It isn't quite clear what you want. If it is Maple code you want to compare then you can e.g. write the code out as a .mpl file (which is ASCII) and then either use diff on them (Linux or Mac OS X) or read these back into Maple and use one of the StringTools commands to compare.

The worksheets are xml files, so your comparison of these may yield differences in the xml code as opposed to real code differences.

RTFM on write, read and StringTools to figure out how to use these.

Mac Dude

 

Consider putting the whole Module with all its procs etc. into a text file with extension .mpl. Add "option package" to the module.

You can then make a package suitable for loading using with(); by doindg the following in a small Maple worksheet:

read("/Applications/Math_Calc/Maple 2015/Packages/Lattice/Lattice4.mpl"); # this is one of mine; put your above .mpl file in here with the full path.

LibraryTools:-Save(Lattice,cat(libname[1],"/Lattice.mla")); # Replace the first "Lattice" with your module name and name the .mla file what you want.

For this to work pre-pend libname with the directory where you want your package to reside. I do that in the startup file for Maple. You do need to preserve what is already in libname else Maple can't find its own modules anymore.

I use Emacs with Joe Riel's maplev mode to edit the .mpl file. Much more convenient than editing in Maple. To update the .mla file just run the small worksheet I suggested above.

M.D.

You already have answers, but since with earlier versions of Maple I ran into exactly the same issue as you did, here is how I used to do it. I did find out later, though, that the Mersenne twister used is rather slow.

#----------------------------------------------------------
(* Procedure Frand(rnge)
   Returns a random float uniformly distributed across range.
   Parameters:   rnge  xmin..xmax the interval
 *)
  Frand:=proc(rnge)
  if (type(rnge,'range')) then
    RandomTools[MersenneTwister]:-GenerateFloat64()*(op(2,rnge)-op(1,rnge))+op(1,rnge)
  else
    RandomTools[MersenneTwister]:-GenerateFloat64()*rnge
  end if

  end proc;

#------

M.D.


 

Preben already answered the basic question how Maple keeps track of local variables: by their address. Other than that, the x are in fact indistinguishable. Except that, if you e.g. try to subs(x=<something>,...) the subs will silently fail and not do anything visible. Made me tear my hair out when I first ran into this situation (due to an unrelated mistake).

The reason why this happens is that you returned an unassigned local variable, which just returns the variable itself. It isn't quite clear to me why you would want to do that, but of course there maybe perfectly valid reasons I just haven't encountered yet. The fact that you cannot do anything with this variable makes some sense: it is procedure-local and not supposed to be visible outside of the proc, much less changeable. It is a bit confusing, however, as no distinction is made.

But what if you actually want to get access to the x? One way to achieve that is to wrap the whole proc in a module and then have x be an export of the module. Like this:

bar:=module()
export x,foo;
foo:=proc(n);
   #local x; # turn this off
   x^n;
end proc;
end module;

Run the proc (I use the long form here):

x:=99;
bar:-foo(2);
                            x := 99
                                2
                               x

and you can access both xes:

x;
bar:-x;
                               99
                               x


If you load module bar using with(bar) [you may need to use option package to do this] then x will implicitly refer to bar:-x and you need to say :-x to get at the x you assigned 99 to [assuming you assign to x first and then use with(bar)]. In this case you have created a new namespace (bar:-) that can be used to keep variables apart.

Finally, in this case repeated calls to foo will not create new instances of x, naturally, as x belongs to module bar. If you want to create several instances of bar you need to use the copy() function; if you assign bar to two different variables you just get two pointers to the same instance.

Obviously now we are on our way to do "OOP lite" in Maple, a feature introduced in Maple 15 that I quite like and use often in my larger packages.

Thanks for the question/post; it exposed an interesting peculiaroty of Maple.

M.D.

@Adam Ledger  I am not sure I fully understand your approach, but I sure have experienced sluggish execution of programs in Maple. ROT13 is a simple algorithm and should not be sluggish. I'd be tempted to implement ROT13 in a table lookup; tables are Maple's associative arrays so you ca use each letter as an index into the table that has the shifted letters. That kind of lookup is quite fast.

If you do numerics, a few hints that may help the situation: First, Maple has the propensity to build huge algebraic expressions if it encounters variables ("names") that are unassigned. The way to detect and/or prevent that is to use evalf often and in case of arrays or vectors to make sure they are declared with "datatype=hfloat". Then, if what is assigned to them isn't a float, it barfs and you can fix the code. You can try evalhf as well but I have run into trouble with it; it is finicky in what can be in its arglist.

It makes sense to evalf an expression before using it in a loop. Evalf will at least simplify any function it can evaluate to a float & in that sense simplify the expression. Sometimes simplify and evalf are needed together to make things faster.

Then there is Compiler:-Compile. I have had relatively little luck with it but you may have better luck. The idea is that you can have a compiled code section which will execute faster. Please read the help on it; I am not an expert in Maple's Compiler operations and there are a number of restrictions.

If you have complicated procs and/or subprocs & the like, the CodeTools package has some tools that will help you to identify the bottleneck in your code. Excessive memory usage and faster than linear growth in executing time with the number of data points (or iterations of a loop) are signs that Maple is trying to do algebraics where you do not want it (even if the final result may be ok).

Cheers,

M.D.

 

 

I don't think so.

Depending on the code to be translated I'd consider using a good editor (Emacs, for example) to make he necessary changes "en masse" using e.g. replace-string. This will work for code snippets.

You can call external code from Maple. Look for examples,external Calling in help. I have never used this.

M.D.

 

In number 1, you use a dot (.) for multiplication. The dot stands in Maple for non-commutative multiplication. I am not sure what this means in this context but when you replace the dot by an asterisk (*) th eintegral evaluates as expected.

 

In number 8 a multiplication sign is missing, making Maple think the first x is a function.

Results (Maple 2015):

int(sqrt(x^3*(ax+b)), x);

                                      (1/2)
                     2   / 3         \     
                     - x \x  (ax + b)/     
                     5                     
     

int(sqrt(x*(ax+b)), x);

                     2               (1/2)
                     - x (x (ax + b))     
                     3                    

 

Mac Dude.

Edit: Forgot your attached file. That one fails because c and v together form a variable cv, which has nothing to do with c*v as I assume you intended.

Result:

int(1/(g-c*v/m), v);
 =
                            /    c v\  
                          ln|g - ---| m
                            \     m /  
                        - -------------
                                c      


Moral: Use 1-d input and not 2-D input, esp. when you are new to Maple & don't need the typesetting. In prefs, on the Display tab change the Input display to Maple Notation. While you are at it, on the Interface tab change the Default format for new sheets to Worksheet.

 

 

 

Herer is your MWE back. The only thing I did was adding a semicolon after the first expression. Without the semicolon, Maple appears to use implied multiplication of your two lines. This is a "feature" of 2-D input.

The way Maple works is that all results generated in an evaluation group is shown at the end of the group. Your first two expressions are in one group. The second two are in separate groups, hence you get the results after each expression.

Constructs like if or do loops always occupy just one group so your options to use grouping as a typesetting tool are limited. Also, if you use equation numbers, only the last result of an evaluation group is accessible by the equation number.

M.D.

MWE.mw

 

It is not clear what you mean by problem 1. The equation numbers are inserted by Maple automatically, as undoubtedly you noticed. You do not get to pick these. If you put an equation into your section, they will be (1.1), (1.2) and so on.

If you refer to a forward reference; i.e. referencing 7 before you get there: Maple does not know these numbers until it evaluates the line. So you cannot reference (7) before Maple has actually assigned it.

Problem 2 is easier: The boldened words are Maple keywords. The italic print indicates that you maybe in an evaluation group. Maple would try to evaluate the section (hit the !!! button to see what it is doing). Since you work in 2-D input mode you can use F5 to switch between text (no evaluation, typeset in roman) and math (evaluation, typeset in italic).

Be aware that Maple also has 1-D input mode; much easier to use if all you want is to perform a calculation. In the Prefs, Interface tab, set Default format for new worksheets to "Worksheet" and on the Display tab, set Input display to Maple Notation. Of course  if you want the typesetting you want the Document type and 2-D input.

I don't know Mma well, but I do not see where Maple lacks flexibiility with the exception of list and array handling, where Maple is much more strongly typed: it has lists, Vectors, Sets, Arrays, Matrix, ... whereas for Mma apparently most of these are lists.

M.D.


I get these all the time although not from Maple. My standard answer is "no". The request is for unsolicited incoming connection requests, i.e. those that your computer or program did not initiate.

My Firewall is "on" & I allow Maple to receive incoming requests (hence no questions). I suspect your system is denying incoming requests for Maple. Check your firewall settings (you'll need to be administrator for that). I bet Maple is in there as being denied. If things work for you, just leave the settings as they are & say "no".

My $0.02,

Mac Dude

 

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