acer

32480 Reputation

29 Badges

20 years, 6 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

By default, units are not combined upon addition.

> restart:
> 3*Unit(microliters)+4*Unit(liters);
                                3 [uL] + 4 [L]

They are combined, if the Units:-Standard package is loaded. The default volume unit for results is meter^3.

> restart:
> with(Units:-Standard):
> 3*Unit(microliters)+4*Unit(liters);
                                 4000003   [ 3]
                                ---------- [m ]
                                1000000000

One can change it, so that microliters is the new default for volume in results.

> restart:
> with(Units:-Standard):
> Units:-UseSystem(Units:-AddSystem(SI,uL));
> 3*Unit(microliters)+4*Unit(liters);
                                 4000003 [uL]

acer

> T := table([ (1,1)=a, (2,2)=s ]);
                     T := table([(1, 1) = a, (2, 2) = s])

> Matrix(2,2,{op(op(eval(T)))});
                                   [a    0]
                                   [      ]
                                   [0    s]

> B[1,2]:=y:
> B[2,1]:=z:
> Matrix(3,3,{op(op(eval(B)))});
                                 [0    y    0]
                                 [           ]
                                 [z    0    0]
                                 [           ]
                                 [0    0    0]

acer

It is the principal third root. There are three cube roots of -1, lying equally spaced around the unit circle in the complex plane.

> evalc( (-1)^(1/3) );
                                            1/2
                               1/2 + 1/2 I 3
 
> convert(%,polar);
                                          Pi
                                polar(1, ----)
                                          3

For a non-principal root,

> surd(-1,3);
                                      -1

There is a short, related, comment in the sqrt help-page (4th bullet item in Description). Compare with exp(1/3 * ln(-1)).

acer

It's not enough to simply assign to the entries B[i,j]. You also have to create B as a matrix or Matrix. Otherwise, B will get created as a table, which is a different structure and not acceptable to matrixplot.

> restart:

> B[1,1]:=4:
> whattype(B);
                                    symbol
 
> type(B,table);
                                     true
 
> plots:-matrixplot(B);
Error, (in plots/matrixplot) invalid input: convert/Matrix
expects its 1st argument, M, to be of type
{Array, Matrix, Vector, array, list}, but received B

> B:=matrix(1,1,[]):
> B[1,1]:=4:
> whattype(B);
                                    symbol
 
> type(B,array);
                                     true
 
> plots:-matrixplot(B); # it works

acer

> f := x -> sin(x):
> RootFinding:-NextZero(f,0.0);
                                  3.141592654
 
> df := x -> evalf(D(f)(x)):
> RootFinding:-NextZero(df,0.0);
                                  1.570796327

> signum( evalf(D[1,1](f)(%)) );
                                      -1

So, the next zero of df, moving positively from 0.0, is at 1.57... and it's a local maximum of f since the second derivative of f is negative at that point. That might be the fastest way when coded efficiently, if just the single next extremum is wanted. If the higher derivative test was not showing the correct sign for what you wanted (maximum or minimum) then NextZero could be re-applied to df starting from the current point, and the test re-checked. Repeat until an extremum of the sort requested is found. It should be pretty straightforward to write a procedure which does all this.

If the function application, f(x), is a univariate polynomial with all other parameters instantiated at known numeric values then fsolve(diff(f(x),x)) would produce all the real roots of the first derivative at once. (Or Student:-Calculus1:-ExtremePoints might be used.) Those could then be sorted, and the higher derivative test could be used to show whether each is maximum or minimum, or to find the smallest positive extremum of the requested type.

acer

It looks as if the solver is getting trapped at a saddle point, depending on the initial value from which it begins solving. (I'm not sure if it matters, that the point lies on a constraint or intersection of constraints. Perhaps the first feasible point tried is that unfortunate point, although if that's the case then it's a pity something else isn't subsequently tried.)

One workaround might be to symbolically simplify the constraints so that it picks a different initial point which allows convergence to some other point . Another workaround may be to provide a judicious (and feasible) initial point directly to the solver.

> x[max] := 10:
> x[min] := 0:
> y[max] := 10:
> y[min] := 0:
> delta := 1:
> b:=2:
> d:=5:
> expr:=((2*c+a-d-2*b)*delta-(1/2)*c+(1/2)*d-b+a)^2/(9*b-9*a);
                                  /3 c             \2
                                  |--- + 2 a - 17/2|
                                  \ 2              /
                          expr := -------------------
                                       18 - 9 a
 
> cons:={b-a >= c-d,
>        (2*b-a-2*c+d)*delta <= 2*b-2*a-2*c+2*d,
>         c-d-b+a <= (2*b-a-2*c+d)*delta};
    cons := {c <= 7 - a, -a - 2 c <= 5 - 2 a - 2 c, c + a <= 16 - a - 2 c}
 
> bounds:= a = x[min] .. b, c = d .. y[max];
                       bounds := a = 0 .. 2, c = 5 .. 10
 
> solA := Optimization:-NLPSolve(expr,cons,bounds,maximize);
Warning, no iterations performed as initial point satisfies
 first-order conditions
               solA := [-0., [a = 0.500000000000000000, c = 5.]]
 
> eval(diff(expr,a),op(2,solA));
                                      0.
 
> eval(diff(expr,c),op(2,solA));
                                      0.
 
> solve(cons union {a>=0, a<=2, c>=5, c<=10});
                                                         2 a
                  {0 <= a, 5 <= c, a <= 1/2, c <= 16/3 - ---}
                                                          3
 
> Optimization:-NLPSolve(
>           expr,
>           solve(cons union {a>=0, a<=2, c>=5, c<=10}),
>           bounds,maximize);
                   [0.0555555555555555525, [a = 0., c = 5.]]

> Optimization:-NLPSolve(expr,cons,bounds,maximize,
>                        initialpoint=[a=0.4,c=5]);
                   [0.0555555555555555525, [a = 0., c = 5.]]

As far as plotting goes, you can get nice visuals using the interactive assistant (toggling the "maximize" checkbox, then Solve button, then Plot button). Compare the plots in the assistant for these two calls,

Optimization:-interactive(expr,cons,a=0..1/2,c=5..16/3);
Optimization:-interactive(expr,cons,a=0..1,c=5..16/3);

acer

What is this shorthand for? Does it stand for a procedure call, or a procedure definition?

   w := proc (Q1, Q2) -->evalf function....

Hopefully, it's not a procedure being (re)created inside a double-loop.

If you post all the code, there's a better chance someone might optimize it well.

acer

Are you saying that, for either subset, you just want the its own members to be linearly independent? If so, then try to find just two pairs. Ask yourself, what does it mean for a pair of vectors to be linear independent? How can you tell quickly that a pair of vectors are linearly dependent?

Or, are you requiring something about both sets at once (a direct sum of the two subspaces spanned by the members of the two sets, say)? What would it mean if a 5x4 matrix, with four of the five vectors as its columns, had a rank of 4?

acer

> restart:
> W := Matrix([[1,0],[0.1,1]]);
                                     [ 1     0]
                                W := [        ]
                                     [0.1    1]
 
> map(limit, LinearAlgebra:-MatrixFunction(W,x^t,x), t=infinity);
                            [      1.           0.]
                            [                     ]
                            [Float(infinity)    1.]

You might also consider looking up the spectral radius of a Matrix. (Especially the first theorem on that page.)

 acer

It seems that one has to supply initial values for either all variables, or for none.

> fsolve({x-y = 1, x+y = 1}, {x=1,y=1}, {x = 0 .. 1});
                               {x = 1., y = 0.}

If that is preceded by trace(fsolve) then one can see that it's setting up the x-range and initial values as specified, and leaving the y range as -infinity..infinity.

acer

In Maple, it is lowercase infinity, not uppercase Infinity.

 sum(1/((6*n)^2-1), n = 1 .. infinity);
                                           1/2
                                       Pi 3
                                 1/2 - -------
                                         12
 
> sum((-1)^(n+1)/(2*n+1), n = 1 ..infinity);
                                        Pi
                                   1 - ----
                                        4

> S := sum((-1)^n/(6*n+5), n = 1 .. infinity);
                                                         11
                  S := - 1/5 - 1/12 Psi(5/12) + 1/12 Psi(--)
                                                         12

> combine(value(combine(convert(S,Int))));
                                                     1/2
                     Pi                1/2      2 + 3
                    ---- - 1/5 - 1/12 3    ln(- ---------)
                     6                                1/2
                                                -2 + 3
 
> kernelopts(version);
            Maple 12.01, X86 64 LINUX, Sep 23 2008 Build ID 363216

acer

Do it four or five times, by hand, and look for a pattern. Then code up the pattern.

Adjust accordingling, if you need to account for constants of integration (which maple does not add in).

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

First 302 303 304 305 306 307 308 Last Page 304 of 337