pagan

5147 Reputation

23 Badges

17 years, 124 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are answers submitted by pagan

Maybe the surfdata command will work for you.

Is the x-y aspect of the data regular? Can you upload a worksheet containing the data? (green up-arrow in mapleprimes editor)

You might get closer with one of your lines of code changed to

  print(``(x^V[1])*``(x^V[2]));

You could also use randpoly. As a simple example

> G:=(x,y)->randpoly([x,y],coeffs=rand(2..10),
>                    expons=rand(5),terms=1):

> ``(G(x,y))*``(G(x,y));

                       /     4\ /     2\
                       \8 x y / \7 x y /

> expand(%);

                                2  6
                            56 x  y 

> ``(G(a,b))*``(G(a,b));

                       /   4  2\ /   4  \
                       \5 a  b / \2 a  b/

> expand(%);

                                8  3
                            10 a  b 

It's a question of what you consider as easier/simpler to code. That's a matter of taste.

The bit of interest is not `randpoly`, of course. It's using ``() around each of the two whole expressions, and not just around their exponents, if you want the bracketing printed as you showed.

The first of the pair below computes the integral (once), and only after that creates an operator. The second of the pair below creates an operator which will compute the integral each time it is called, and then subsequently evaluate the result at the value of x.

F:=unapply(int(x^2,x),x);

F:=x->eval(int(t^2,t),t=x);

Or, as 2D Math input you could enter it like this. When the popup disambiguation dialogue shows, select "function definition" from the list of suggestons.

F(x):=eval(int(t^2,t),t=x)

Here is a modified version of the worksheet, using the Units:-Standard package to bring about the simplifications automatically.

Pre-Design_modifie.mw

There is still a (pre-existing) issue with the dimensions of the terms in the i_Comp formula.

It appears to be in the parent module.

  restart:
  kernelopts(opaquemodules=false): 
  print(Student:-PlotOptionsWindow);

  restart:
  showstat(Student::PlotOptionsWindow);

What is happening, I think, is that the site is indexing words appearing in the collection/summary pages of brief descriptions of posts/questions.

Of course, those brief summaries should not be used for indexing keywords. If a keyword appears in a post then the indexed will find and note it at that original location. And that should be enough.

I described this in paragraphs 4 and 5 of this post, in Nov 2010. I described other site indexing points there as well. And while there was no response in that thread, I hope that some of it was considered in the upcoming changed and improvement to this site.

Why use an array of two vectors, when you could use a 2-dimensional Array or a Matrix?

Are you really using the now-deprecated (lowercase) `array` and `vector`?

The rtable_scanblock command has an option to do this, for Array, Matrix, or Vector.

> restart:

> A:=ArrayTools:-RandomArray(20, 10, generator=-1.0..1.0):

> rtable_scanblock(A,[rtable_dims(A)],'Average');
                                0.4977240547

> M:=LinearAlgebra:-RandomMatrix(20, 10, generator=-1.0..1.0):

> rtable_scanblock(M,[rtable_dims(M)],'Average');
                               -0.01724817976

> V:=LinearAlgebra:-RandomVector(20, generator=-1.0..1.0):

> rtable_scanblock(V,[rtable_dims(V)],'Average');
                               -0.02840733230

> ArrayTools:-AddAlongDimension(ArrayTools:-Reshape(A,[200]))/200.0;
                              0.497724054714820

> ArrayTools:-AddAlongDimension(ArrayTools:-Reshape(M,[200]))/200;
                               -0.01724817976

> ArrayTools:-AddAlongDimension(V)/200;
                               -0.002840733230

Why does rtable_scanblock produce a float result for exact data (when the length is more than one)?

> rtable_scanblock(Vector([1/3,1/7]),[1..2],'Average');
                                0.2380952381

> ArrayTools:-AddAlongDimension(ArrayTools:-Reshape(Vector([1/3,1/7]),[2]))/2;
                                     5 
                                     --
                                     21

> evalf(%);
                                0.2380952381

There are several ways to do this, and which is easiest may depend on whether you have an expression or a procedure, or even a precomputed 3D plot structure already.

But here is one quick example, using an operator with 'option remember' so as to avoid unnecessary recalculation of the z-values while determining points' color values.

> restart:

> expr:=3*x-sin(x*y);
                         3 x - sin(x y)

> fexpr:=unapply(expr,[x,y],proc_options=[remember]):

> plot3d(fexpr,-4..4,-6..6,axes=box,color=[signum@fexpr,-signum@fexpr,0]);

In recent versions of Maple Arrays are "growable", using round-bracket syntax for element reference on the left-hand-side of the assignment statement. (See ?updates,Maple12,programming )

> foo:=Array(1..200):

> foo(210):=13;

[ 1 .. 210 1-D Array ]
[ Data Type: anything ]
foo := [ Storage: rectangular ]
[ Order: Fortran_order ]

> foo[208];

0

> foo[210];
13

An alternative would be to use a table (same square-bracket syntax as Arrays for assignments, but without first creating foo as an Array). A big difference is that undefined Array entries are zero (or some fill-value) by default, whereas for tables they remain unassigned.

If you really don't know any upper bound for the number of entries, in advance, then a table might be more efficient. Growing an Array can still involve some copying/creation/garbage-collection, but it might be better than list-appending which can make your implementation O(n^2) in memory use.

Another alternative, if you know an upper bound on the number of possible entries, is to create a maximally sized Array up front, keep track of admissions with a counter, and then resize at the end.

I haven't tested growing Arrays in a while, but I have a recollection that it might behave as if slightly more (10%??) extra space gets added "under the hood" when grown. If that is true then further re-growing (up to some amount) may be done whilst avoiding yet more memory management. You could test the truth of this.

Create a .mla library archive using `march`or LibraryTools:-Create, then set libname to point first at its location, then use savelib the procedure to that archive. If you do that, then the procedure will be available in any new session which also has libname pointing to that library's location.

That, in my opinion, is the best way. (It could be better documented, as some help pages describe .lib file name extensions rather than the correct modern .mla file name extension for a library archive. sigh). It will run fastest. But you should still save the source of the procedure (in the parent worksheet, or wherever).

The second best way, also not well documented as a whole task, is to write out the procedure to a .mpl file and then use subsequent reads of it in new sessions. (This may require editing of the text file, if you use the GUI's menu to Export and the worksheet contains stuff other than just the procedures in question. You might as well copy and paste to a file using a command, or with the mouse...) This will not run as fast. The plaintext will contain the very source.

A worse way is to try and set up inter-worksheet references in any new worksheets.

You seem to be using 2D Math input. Enter that y-axis label, but without the double-quotes around it. Select all of that y-axis label with the mouse pointer, and then right-click to get the context menu. In that pop-up context menu, choose the action 2-D Math -> Convert To -> Atomic Identifier.

That worked for me.

What this does, behind the scenes, is replace that label with the 1D Maple notation name `#mrow(msub(mi("S0"),mn("2")),mo("⁢"),mfenced(mi("%")))` which gets nicely typeset.

You have an (extra) misplaced closing bracket before the comma, just before h[1]=k[1]..4.

You cannot use the name k as that loop index while also using the table reference k[1] as that sum index. Either replace the loop index name as kk instead of k, or make all the occurences of k[1] be the same atomic identifier (or whatever other name you'd like).

Put a full colon after the od (or end do), to suppress all normal output of the loop. Then wrap the display inside print to force its results to be printed.

restart;
a:=1;
with(plots):
for n from 1 by 2 to 3
  do;
  P1:=plot(sqrt(a)*cos((n*Pi*x)/2*a)+1,x=-a..a,y=0..2,style=line):
  P2:=plot([[[-a,0],[-a,10]],[[a,0],[a,10]]],x=-a..a,y=0..2,colour=blue):
  print(display({P1,P2},scaling=constrained,title=`wavefunction`));
od:

You could alternatively put the individual plot calls inside the display, and leave the rest as it is. But the above is a more general solution, if you have other things going on inside the loop that you don't want shown.

restart;
a:=1;
with(plots):
for n from 1 by 2 to 3
do;
  display({
      plot(sqrt(a)*cos((n*Pi*x)/2*a)+1,x=-a..a,y=0..2,style=line),
      plot([[[-a,0],[-a,10]],[[a,0],[a,10]]],x=-a..a,y=0..2,colour=blue)
          },scaling=constrained,title=`wavefunction`);
od;

It works as 1D Maple notation, but not if pasted as 2D Math input.

It looks as if the 2D Math parser does not know to accept that "alternate spelling" syntax for keyword parameters.

This is just one of many reasons why I would suggest doing non-trivial programming in 1D input mode.

Is this of any help?

> T:=(1+1/n)^((1/2)/(sum(1/((2*k+1)*(2*n+1)^(2*k+1)), k = 0 .. m))):

> series(T,n=infinity,10) assuming m>0;

                                   /1 \
                         exp(1) + O|--|
                                   | 7|
                                   \n /

> MultiSeries:-series(T,n=infinity,10) assuming m>5;

                                  / 1 \
                        exp(1) + O|---|
                                  | 10|
                                  \n  /
First 16 17 18 19 20 21 22 Last Page 18 of 48