acer

32333 Reputation

29 Badges

19 years, 326 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The ImportMatrix command should be able to handle this.

acer

There are several ways to do this. Here are two.

restart:                         

f:=RandomTools:-Generate(list(integer(range=-30..50), 5), makeproc):

seq( f(), i=1..4 );                                                 

    [14, -25, 28, 13, 7], [38, -4, -14, 3, -13], [21, 25, 12, -6, 29],

    [-17, 19, 16, -23, 15]

restart:                                                            

f:=rand(-30..50):                                                   

seq( [seq(f(),j=1..5)], i=1..4 );                                   

    [14, -25, 28, 13, 7], [38, -4, -14, 3, -13], [21, 25, 12, -6, 29],

    [-17, 19, 16, -23, 15]

I expect that there are several faster ways.

I expect that you could also use Statistics:-Sample and a discrete distribution.

Here's another one,

restart:

f:=(n,k)->convert(LinearAlgebra:-RandomMatrix(k,n,generator=-30..50),
                  listlist)[]:

f(5,4);

    [38, 43, 9, 23, 36], [-4, -18, -5, -9, -12], [-22, -24, -5, 14, 21],

    [28, 21, 46, -11, 15]

Do you need it very, very fast? Do you need to create a large number of these lists? Do you need to create them all up front, before you work on them?

acer

Change that last line to this,

plots:-display(p1,p2);

The display comamnd you're trying to use is part of the plots package. Either reference it as plots:-display or first load the package using the command with(plots): and then call it as just display.

acer

Perhaps I don't understand what your trying to accomplish. But why not use exact values for x?

for x from -1 by 0.5 to 1 do print(x, evalf(0^(x^2), 20)) end do; 

                                    -1, 0.

                                   -0.5, 0.

                             0., Float(undefined)

                                    0.5, 0.

                                    1.0, 0.

for x from -1 by 1/2 to 1 do print(x, evalf(0^(x^2), 20)) end do;

                                    -1, 0.

                                   -1/2, 0.

                                     0, 1.

                                    1/2, 0.

                                     1, 0.

for x from -1 by 1/2 to 1 do print(x, evalf(0.0^(x^2), 20)) end do;

                                    -1, 0.

                                   -1/2, 0.

                                     0, 1.

                                    1/2, 0.

                                     1, 0.

And of course there are lots of ways that you can make the behavior conditional upon the value of x. Examples include,

for x from -1 by 0.5 to 1 do
  print(x,`if`(x=0,1.0,evalf(0^(x^2), 20)));
end do;

                                    -1, 0.

                                   -0.5, 0.

                                    0., 1.0

                                    0.5, 0.

                                    1.0, 0.

for x from -1 by 0.5 to 1 do                
  print(x,evalf(0^(`if`(x=0,0,x^2)), 20));
end do;

                                    -1, 0.

                                   -0.5, 0.

                                    0., 1.

                                    0.5, 0.

                                    1.0, 0.

acer

Change the square brackets in the assignment to Eqns (inside plotsol1s) to round brackets.

Round brackets are expression delimiters. Square brackets create a list.

acer

restart:

eq1 :=  x^2-y^2 = a*z^2:
eq2 := x-y = a*z:       

normal(eq1/eq2);        

                                   x + y = z

acer

See this help-page on Maple initialization files.

That file should be a plaintext file (but without .txt as filename extension). It should contain Maple commands in 1D Maple Notation (plaintext).

In this case it should contain a line which redefines the Maple variable libname. For example.

libname:= `c:/maple12/advisor`, libname:

and of course edit that to be the place you actually install it.

acer

Your line of code,

   SetVariables = proc( vars:: list, time )

should be

   SetVariables := proc( vars:: list, time )

so that it is an assignment statement.

Also, the line

   for i from 1 to var N do

in the body of the SetVariables procedure is not valid syntax. It might have been intended as,

   for i from 1 to varN do

acer

restart;

`&as`:=proc(a::uneval) eval(`assuming`([a],[args[2..-1]])); end:

sqrt(x^2) &as (x>0);

                               x

sqrt(x^2) &as (x<0);

                               -x

(sqrt(x^2)*sqrt(y^2)) &as (x>0, y>0);

                              x y

(sqrt(x^2)*sqrt(y^2)) &as (x<0, y>0);

                              -x y

(sqrt(x^2)*sqrt(y^2)) &as (x>0 and y>0);

                              x y

(sqrt(x^2)*sqrt(y^2)) &as (x>0 and y<0);

                              -x y

acer

This weird behaviour seems to have started with Maple 18.00.

restart:

hhh:=400/Unit(1/kg);
                              400       
                       -----------------
                                  / 1  \
                       Units:-Unit|----|
                                  \'kg'/

with(Units:-Standard,`/`,`*`,normal);
                         [/, *, normal]

simplify(hhh);
                     400 Units:-Unit('kg')

normal(hhh); # ???
                                     / 1  \
                     -400 Units:-Unit|----|
                                     \'kg'/

:-normal(hhh);
                              400       
                       -----------------
                                  / 1  \
                       Units:-Unit|----|
                                  \'kg'/

hhh;
                              400       
                       -----------------
                                  / 1  \
                       Units:-Unit|----|
                                  \'kg'/

1/hhh; # ???
                       1                   
                    - --- Units:-Unit('kg')
                      400                  

hhh/1; # ???
                                     / 1  \
                     -400 Units:-Unit|----|
                                     \'kg'/

I will submit a bug report.

acer

Is it a part of your problem that Maple is parsing your input as if it were multiplication, ie, like D(F) * (x) ?

If so and if you are using Maple 2015 then this might be related to the GUI preference for so-called Smart Operators.

acer

@Tycoon51 If plots:-matrixplot satisfies your needs then great. You did state that you wanted the x- and y-axes to be coordinates of the 2-dimensional "array".

It may be worth mentioning that sometimes one wants the coordinate values to be interpreted as if from some pair of x- and y-ranges, rather than just as discrete coordinate values. In such cases the command plots:-surfdata can help, as it also accepts optional arguments to specifiy the x- and y-ranges to be used for generating x- and y-axis tickmarks.

A:=Matrix(1..51, 1..31, (i,j)->evalf( ((j-1-15)*2/30)^2 * sin(2*Pi*(i-1)/50)) ):

plots:-matrixplot(A, axes=box);

plots:-surfdata(A, 1..51, 1..31, axes=box);

plots:-surfdata(A, 0..2*Pi, -1..1, axes=box);

Why do you need each entry to be read back in as an individual assignment statement?

Why not use ExportMatrix to write all the entries to a file at once, after the loop finishes? And then import then all at once using ImportMatrix in your new sessions?

If you prefer you could still export each entry individually using fprintf (or other) inside the loop. But you could still re-import them in bulk, using ImportMatrix (which should be faster as well as simpler).

You can make the call to ImportMatrix be done with a single assignment. Eg,

M := ImportMatrix(outfile,...)

So in this way you can have your values be in a data file, rather than in a file of Maple commands.

acer

I'm not really understanding your comments that motivated this, but you can write your own custom `D/A` extension.

I'm not really sure that I understand why you want to have it work for D[...]A(a,b,c) rather than with 2-argument `eval` applied to the result like say eval(diff(A(s,t,m),...),[s=a,t=b,m=c]).

Of course it's up to you to make sure that it does what you want.

I just made up these examples, and the results may or may not make sense. It's just to illustrate the idea.

Here's the first example,

restart;

A:=proc(x,y,m)
  if m>0 then
    return B(x) + B(y) + 'A'(x,y,m-1);
  else
    return 1;
  end if
end proc:

(D[1](A))(1,2,3);

(D[1](A))(1, 2, 3)

`D/A`:=proc(d)
  if nops(d)=1 then
    if d[1]=1 then
      return proc(x,y,m)
        if m>0 then
          return D(B)(x);
        else
          return 0;
        end if
      end proc;
    elif d[1]=2 then
      # Now, how shall we handle the derivative of this returned proc?
      return proc(x,y,m)
        if m>0 then
          return D(B)(y) + eval(subs(__d=d[],'D[__d](A)')(x,y,m-1));
        else
          return 0;
        end if
      end proc;
    end if;
  else
    # You may wish to also handle case of nops(d)>1 , etc.
  end if;

  # default return value
  subs(__d=d[],'D[__d](A)');
  
end proc:

D[1](A);
D[2](A);

proc (x, y, m) if 0 < m then return (D(B))(x) else return 0 end if end proc

proc (x, y, m) if 0 < m then return (D(B))(y)+eval((subs(__d = [2][], 'D[__d](A)'))(x, y, m-1)) else return 0 end if end proc

(D[1](A))(s,t,0);

0

(D[1](A))(s,t,1);

(D(B))(s)

(D[2](A))(s,t,0);

0

(D[2](A))(s,t,1);

(D(B))(t)

(D[2](A))(s,t,2);

2*(D(B))(t)

(D[2](A))(s,t,3);

3*(D(B))(t)

 

Download sometoyD.mw

And here's another example,


restart;

A:=proc(x,y,m)
  if m>0 then
    return B(x) + B(y) * 'A'(x,y,m-1);
  else
    return 1;
  end if
end proc:

(D[1](A))(1,2,3);

(D[1](A))(1, 2, 3)

`D/A`:=proc(d)
  if nops(d)=1 then
    if d[1]=1 then
      return proc(x,y,m)
        if m>0 then
          return D(B)(x) + B(y) * eval(subs(__d=d[],'D[__d](A)')(x,y,m-1));
        else
          return 0;
        end if
      end proc;
    elif d[1]=2 then
      # Now, how shall we handle the derivative of this returned proc?
      return proc(x,y,m)
        if m>0 then
          return D(B)(y) * 'A'(x,y,m-1)
                 + B(y) * eval(subs(__d=d[],'D[__d](A)')(x,y,m-1));
        else
          return 0;
        end if
      end proc;
    end if;
  else
    # You may wish to also handle case of nops(d)>1 , etc.
  end if;

  # default return value
  subs(__d=d[],'D[__d](A)');
  
end proc:

(D[1](A))(s,t,0);

0

(D[1](A))(s,t,1);

(D(B))(s)

(D[1](A))(s,t,2);

(D(B))(s)+B(t)*(D(B))(s)

(D[1](A))(s,t,3);

(D(B))(s)+B(t)*((D(B))(s)+B(t)*(D(B))(s))

(D[2](A))(s,t,0);

0

(D[2](A))(s,t,1);

(D(B))(t)*A(s, t, 0)

(D[2](A))(s,t,2);

(D(B))(t)*A(s, t, 1)+B(t)*(D(B))(t)*A(s, t, 0)

(D[2](A))(s,t,3);

(D(B))(t)*A(s, t, 2)+B(t)*((D(B))(t)*A(s, t, 1)+B(t)*(D(B))(t)*A(s, t, 0))

 


Download anothertoyD.mw

acer

A result that agrees with that of member vv, but via a change of variables rather than by switching the order of integration.

restart;

with(VectorCalculus):

v1 := x^2 + y - sin(z):

v2 := x^2 + 1/y - 2*z:

v3 := y^2 + 3*x + z:

vv := VectorField(<v1, v2, v3>, 'cartesian'[x, y, z]):

NULL

G := Flux(vv, Sphere(`<,>`(0, 0, 0), r), inert);

Int(Int(-sin(phi)*(sin(phi)*cos(theta)^3*cos(phi)^2*r^3+sin(phi)*cos(theta)^2*sin(theta)*cos(phi)^2*r^3-cos(theta)^2*cos(phi)^3*r^3-sin(phi)*cos(theta)^3*r^3-r^3*sin(phi)*cos(theta)^2*sin(theta)+cos(theta)^2*cos(phi)*r^3+cos(theta)*sin(theta)*cos(phi)^2*r^2+cos(phi)^3*r^3-3*sin(phi)*cos(theta)*cos(phi)*r^2+2*r^2*cos(phi)*sin(phi)*sin(theta)+sin(phi)*cos(theta)*sin(r*cos(phi))*r-cos(theta)*sin(theta)*r^2-cos(phi)^2*r^2-cos(phi)*r^3-1)*r, phi = 0 .. Pi), theta = 0 .. 2*Pi)

``

This is easier if the dummy variables of integration are not escaped locals.

 

G := subsindets(G, name, convert, `global`):

 

Do a change of variables on the inner integral, then  get its value.

 

value(IntegrationTools:-Change(op(1, G), cos(phi) = t, t));

-r*(-(3/8)*Pi*cos(theta)^3*r^3-(3/8)*Pi*cos(theta)^2*sin(theta)*r^3-(4/3)*cos(theta)*sin(theta)*r^2-(2/3)*r^2-2)

 

Replace the inner integral with that result. Then get the value of the outer integral.

 

value(subsop(1 = %, G));

(4/3)*Pi*r^3+4*Pi*r


Download flux3.mw

acer

First 217 218 219 220 221 222 223 Last Page 219 of 336