acer

32747 Reputation

29 Badges

20 years, 112 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

This is the sort of task where, for selecting a "good" method, it can make a big difference whether you want just a few values (digits), or many or most of them.

Suppose that you want just a few values. You could do something quite simple like this,

> p := proc(n) Rounding:=0; op(1,evalf[n](Pi)) mod 10; end proc:

> st:=time(): p(30000); time()-st;
                                       7
 
                                     0.065

The above code is "ok",  if just a few digits are wanted. But it's not efficient if you want many digits. The above example, for the 30000th digit, may not be representative of the timing since Maple might have that many digits hard-coded.

Also, the above routine `p` has its efficiency affected by whether one starts with the lower or the higher digits (on account of the evalf remember table allowing lower digits to be computed more quickly by chopping the previously computed higher accuracy results). For example,

> restart:
> p := proc(n) Rounding:=0; op(1,evalf[n](Pi)) mod 10; end proc:
> kernelopts(printbytes=false):
> st:=time(): [seq(p(i),i=49900..50000)]: time()-st;
                                    17.909
 
> restart:
> p := proc(n) Rounding:=0; op(1,evalf[n](Pi)) mod 10; end proc:
> kernelopts(printbytes=false):
> st:=time(): [seq(p(i),i=50000..49900, -1)]: time()-st;
                                     0.196

If you wanted them all, up to some Nth place, then you could just use convert/base (or an improved variant on that, possible using repeated irem calls, say).

As written above the `nthpi` routine will not produce all correct results. The first incorrect digit it produces is the 12th, I think. (That's because round-up can affect more than just the previous digit...)

acer

See here.

acer

The problem is that a space (for implied multiplication), or an explicit multiplication sign (ie, *) is missing between (4*sigma^2-x^2-y^2) and the next bracket that follows it.

There is also a missing multiplication indicator after the second instance of signa^2, right before (x^2+y^2).

Without either of those, the 2D Math parser is interpreting these input parts as function calls. Hence the erronous output with things like 2(something), 1(something), and 6(something), after substituition.

acer

plots:-listplot( [seq(X[i],i=1..50)] );

acer

You could post the actual example.

Do you want exact, or floating-point results? Is it a polynomial of one variable or of several variables? If it is univariate, then you could pass it to fsolve for floating-point results. If the problem is that the form of the exact results from solve don't appear to match your expectation, then suggestions might be made if you post the example.

acer

Have a look at the help-page for rtable_scanblock. That routine can find max/min and locations for Matrix/Vector/Array.

> V:=<1,4,8,2>:

> rtable_scanblock(V, [1..3],
>                  (val,ind,res) -> `if`(val > res[2],[ind,val],res),
>                  [[1],V[1]]);
                                   [[3], 8]

> op(%[1]);
                                       3

Note that your [1,4,8,2] is a list, not a Vector.

acer

plot( 23*sin(x) + x - 1, x=-35..35 );

RootFinding:-Analytic(23*sin(x)+x-1, x=-100-0.1*I..100+0.1*I );

seq(eval(23*sin(x)+x-1,x=t), t in [%]);

acer

Powell := (M,N) -> (first(M,N),second(M,N)):
Powell(4,5); # for example

MyMat := Matrix(100,2):

for N from 1 to 10 do
  for M from 1 to 10 do
    MyMat[10*(N-1)+M,1],MyMat[10*(N-1)+M,2] := Powell(M,N);
  end do:
end do:

interface(rtablesize=100):
MyMat;

The interface(rtablesize) call only needs to be done once, and only serves if you wish to get the entries printed out to the Maple interface.

For the other aspect, of selecting just some of the values, you could use the following technique,

> Powell := (M,N) -> (first(M,N),second(M,N),third(M,N),fourth(M,N),fifth(M,N)):
> g:=[Powell(7,11)];
 g := [first(7, 11), second(7, 11), third(7, 11), fourth(7, 11), fifth(7, 11)]

> g[2],g[3];
                          second(7, 11), third(7, 11)

That is to say, the double loop might look like this,

for N from 1 to 10 do
  for M from 1 to 10 do
    g:=[Powell(M,N)];
    MyMat[10*(N-1)+M,1],MyMat[10*(N-1)+M,2] := g[2],g[3];
  end do:
end do:

The Matrix() constructor also admits an operator as an initializer, and that could likely be made to work here too (without all that looping). But maybe you have other things that you'd eventually want to happen inside your loop. And it's useful to get familiar with the loop and assignment syntax.

acer

How far have you gotten with any of these, so far?

Write down the cosine law (and/or the sine law). Fill in some of the variables with the information you're given. Figure out which of the other variables relate to the piece that you're asked to find. Solve for that variable.

acer

> expr := (beta*p-beta-p)*alpha/(p*(beta-1)):

> simplify(expr-(alpha+beta/p),{alpha=1-beta});

                                       0

> eval(collect(expr,p),beta=1-alpha);
                                       1 - alpha
                               alpha + ---------
                                           p

> collect(simplify(simplify(expr,{alpha+beta=1})),p) assuming alpha>0, beta>0;
                                       1 - alpha
                               alpha + ---------
                                           p
 
> subsindets(%,identical(1-alpha),t->beta);
                                         beta
                                 alpha + ----
                                          p

> subsindets(collect(expr,p),identical(beta-1),t->-alpha);
                                         beta
                                 alpha + ----
                                          p

acer

You forgot spaces before the opening round-brackets, when you typed in

d(27*d^2-40)^3

and

x(3*x^3-9*x^2+20)

Without the space (to imply multiplication) Maple interprets those as function calls to x() and d().

acer

The Matrix formed from those three vectors will have zero as its determinant when that Matrix has a rank of less than three.

> (u,v,w) := <-2,-5,5>, <1,7*a,-2>, <3,3,a>;

                                     [-2]  [ 1 ]  [3]
                                     [  ]  [   ]  [ ]
                          u, v, w := [-5], [7 a], [3]
                                     [  ]  [   ]  [ ]
                                     [ 5]  [-2 ]  [a]
 
> with(LinearAlgebra):

> values := [solve( Determinant( <u|v|w> ) )];
                                        1/2               1/2
                                    2962              2962
                values := [- 25/7 - -------, - 25/7 + -------]
                                      14                14
 
> seq( Rank( eval(<u|v|w>,a=values[i]) ), i=1..nops(values) );
                                     2, 2

acer

It seems most likely (to me) the the request is how to assign entries to a Matrix which already exists. Hopefully the submitter will clarify, if needed.

M := Matrix(10,10):
for i from 1 to 10 do
  for j from 1 to 10 do
     M[i,j] := Xlocal(i,j);
  end do;
end do;
M;

The above looping is ok. But really the answer depends on what form your Xlocal is in. If Xlocal is a list of lists or a Maple table (with the right sort of indices) already then you could just pass it directly to the Matrix() constructor. Eg,

Xlocal := [[1,3],[5,7]]:
Matrix(Xlocal);
Xlocal := table([(1,2)=17,(3,2)=11,(3,3)=13]):
Matrix(3,3,Xlocal);

If Xlocal is a procedure, then you could pass it to the Matrix() constructor as the initializer. Eg,

Xlocal := (i,j) -> i*sin(i+j):
Matrix(3,3,Xlocal);

acer

The B is typesetting of Beta. See the help-page for that special function by issuing the command ?Beta.

ps. Do not try define functions in Maple in this way,

f(x):=(1-x^(3/(2)))^(2/(3));

What that actually does is assign to f as if it had a remember table. It may not always behave as you expect. It actually does this,

> f(x):=(1-x^(3/(2)))^(2/(3));
                                         (3/2) (2/3)
                           f(x) := (1 - x     )
 
> eval(f);
               proc() option remember; 'procname(args)' end proc
 
> op(4,eval(f));
                                         (3/2) (2/3)
                        table([x = (1 - x     )     ])

To instead assign f as an expression, do it like this,

f:=(1-x^(3/(2)))^(2/(3));

eval(f, x=1/2); # evaluate at a point

Or, to assign f as a procedure (function) do it like this,

f:= x -> (1-x^(3/(2)))^(2/(3));

f(1/2); # evaluate at a point

acer

I suspect that the point of the exercise is to show that you can compute that more easily by going (temporarily) through polar forms.

Suppose that you have two complex numbers a and b. It can be awkward to raise those to high powers by hand. But if you first convert to polar form, then you can combine the radii and the angles more "easily", and then convert back. Notice how, below, one doesn't have to compute a^12 or b^11 by fully expanding out the complex numbers.

> a := 2-5*I:
> b := 4+I:
> abs(a)^12, 12*argument(a);
                          594823321, -12 arctan(5/2)
 
> abs(b)^11, 11*argument(b);
                                   1/2
                         1419857 17   , 11 arctan(1/4)
 
> rationalize( abs(a)^12 / abs(b)^11 );
                                            1/2
                                594823321 17
                                ---------------
                                   24137569
 
> simplify( arctan( tan(12*argument(a)-11*argument(b)) ) );
                                   3326168023240553
                           -arctan(----------------)
                                   1030781181093988

I'll leave it to you to see how best to convert back to rectangular complex coordinates. Of course, Maple can do it for you either way, easily.

> a^12/b^11;
                    -1030781181093988   3326168023240553
                    ----------------- + ---------------- I
                     34271896307633      34271896307633

> r,theta := op(convert(%,polar));
                                  1/2
                      594823321 17             3326168023240553
          r, theta := ---------------, -arctan(----------------) + Pi
                         24137569              1030781181093988

> r*cos(theta)+I*r*sin(theta);
                    -1030781181093988   3326168023240553
                    ----------------- + ---------------- I
                     34271896307633      34271896307633

acer

First 306 307 308 309 310 311 312 Last Page 308 of 341