tomleslie

13876 Reputation

20 Badges

15 years, 169 days

MaplePrimes Activity


These are answers submitted by tomleslie

Haven't been able to obtain a 'symbolic' result, but it is pretty simple to generate 'numeric' values, if that is acceptable?. See the attached

erfcInt.mw

I only ask because

  • I don't know any way to `force` multiple solutions from LPsolve. Even if I did, it might take as long as DS:-(
  • For small(ish) lists, it i possible to generate the required answers by 'direct enumeration', rather than using any kind of  optimization process

The attached code shows one implementation of the 'direct enumeration` process.,

doParts.mw

Algorithm is as follows

  1. Check that the sum of all elements in the input list is even, otherwise no exact partition is possible
  2. Generate all possible sublists of the input list. If the input list has n elements then one only needs to consider sublists with lengths from 1 to n-1.
  3. Throw away all sublists whose element-sum is not equal to half the element-sum of the input list
  4. Check all pairwise combinations of the remaining sublists to see which pairs can reconstruct the original list

On my machine, this takes ~0.5secs to run on 10-element input lists, but this explodes to 15secs for 12-element input lists

When attempting to run your code, I get the error message

Error, final value in for loop must be numeric or character

This occurs because the variable 'ni' is used as the final value in a 'for loop'. However the variable 'ni' has not been assigned a numeric value. You cannot run a for loop to a final value which isn't numeric.

See the annotated code attached where I have indicated the point where the fatal error occurs. The variable 'ni' is used prior to this point (as indicated), which may not be what you desire(?), but probably isn't fatal

codeProb.mw

I haven't even attempted to run the rest of this code with a numeric value for 'ni' - simply because I have no idea what value would be appropriate!

then

n:=10;
b:=Matrix(n,1, i->add(1/(i+j-1), j=1..n));

ought to work

With the "spirit" of the OP's original code - using the geom3d package to define points, the plane, and the equation of the plane. Roughly half of this code is required just to ensure that the  output is in the precise form specified by the OP.

NB I'm pretty sure that this will be subtantially "slower" than the straightforward LinearAlgebra() solution - but on "small" problems.....

getEq:= proc( L1::listlist )
                        local expr;
                        uses geom3d:
                     #
                     # generate geom3d "points"
                     #
                        seq( point(p||j, L1[j]), j=1..3);
                     #
                     # Generate geom3d plane
                     #
                        plane(p, [p1,p2,p3], [x,y,z]);
                     #
                     # get plane equation, reduce common factors,
                     # and sort to required order
                     #
                        expr:=sort( primpart(lhs(Equation(p))));
                     #
                     # ensure lead coefficient of sorted plane
                     # equation is positive
                     #
                        expr*signum(lcoeff(expr))=0;
             end proc:
map(getEq, L);

 

Given the two matrices in four original question, the following code will genrate them programatically

  Aold:= Matrix
              ( 5,
                10,
                (i,j)->j+10*(i-1)
             );
  Anew:= Matrix
                ( [ seq
                    ( seq
                      ( [ Aold[k-1, j], Aold[k, j+1], Aold[k+1, j], Aold[k, j-1] ],
                        j=k..8,2
                      ),
                      k=2..4
                  )
                ]
             );

 

One simple one

radius:=1:
p1:=plottools:-circle([0,0],radius, color=red):
tx:= [ seq( [1.1*radius, Pi/2-j*2*Pi/12, convert(j, string)], j=1..12) ]:
p2:=plots:-textplot(tx, 'font'=["times","roman",20], coords=polar):
plots:-display([p1,p2], axes=none);

 

The LinearAlgebra package contains 'analogues' of the basic map/map2 functionality.

Check out LinearAlgebra:-Map() and LinearAlgebra:-Map2() - excerpt from Maple help below with added emphasis

The Map and Map2 commands are identical to the map and map2 commands, respectively, except that if expr is a Matrix or Vector, then f is applied to the elements of that Matrix or Vector, and the application is done in-place.

There are various other commands within the LinearAlgebra package which accept an in-place option: for example Add(), Multiply(), Zip()

Try typing LinearAlgebra/inplace on the Maple help page

 

 

a := abs(x);
b := (3/4)*x^2+1/4;
maximize(abs(a-b),x=-1..1);

works for me! If you need visual justification, then look at

plot([a,b], x=-1..1);

 

 

Issue seems to be linked with convert/piecewise (not sure why you need/use it) because

int(f(x)*f(y)*x*x*abs(x+y),x=-infinity..infinity,y=-infinity..infinity);

returns 3/sqrt(Pi), which evaluates to 1.692568750

Assuming that you are referring to the examples worksheet

Modeling Objects with Modules

then simply reading the code makes it obvious that executing the elapsed() method returns the time since the clock was started or reset) AND issues a halt() statement - ie stops the clock.

If you just want to know the time since the clock was started, and leave the clock running, use the sample() method instead - this provides its output as now()-checkpoint, where checkpoint is the time the clock was started (or reset), and now() is the current time.

If this isn't what you want then you are going to have to clarify.

sols:=solve([f[1](x,y,z), f[2](x,y,x), f[3](x,y,z)], [x,y,z]):

will return four solutions.

sols[1] and sols[2] are quite 'simple', although both have y=0.

sols[3] and sols[4] are pretty complicated

I implemented(?) the algortihm as given in the stackoverflow reference.

NB I do not pretend to understand why this algorithm 'works'. Somwhat to my surprise it seems to give the correct answer. At least the distance matrix for the points generated by the stackoverflow algorithm and that calculated from your original 'city' coordinates appear to be the same (within roundoff)

See the attached.

revEngSol.mw

Since the linalg package is deprecated (and you list your copy as Maple2016), I have implemented the algorithm using commands from the later LinearAlgebra package

When I run the code in Maple 2016,

with(Optimization):
Minimize(4*x^2+4*x*y, {x^2*y = 16}, assume = nonnegative)

returns
[47.9999999999998721, [x =2.0000000000965907, y = 3.9999999996136215]]

So the minimum is 47.9999999999998721, obtained at x =2.0000000000965907, y = 3.9999999996136215.

Now that is a pretty good floating point approximation to a minimum of 48 obtained at x=2, y=4. So what is your problem? Maybe you get a different answer in a different Maple version?

 

Problem is with the definition of the function delta(). I made a slightly different assumption about what you want. That delta(x)=1 if x<=0, and delta(x)=0 otherwise. This also runs and produces meanningful(?) output.

See the attached

recur.mw

First 174 175 176 177 178 179 180 Last Page 176 of 207