Kitonum

21860 Reputation

26 Badges

17 years, 238 days

MaplePrimes Activity


These are replies submitted by Kitonum

@Carl Love   Thanks for the explanation.

@Carl Love   What is the meaning of this assignment  r:= table() ?

The next version works similar:

twinprimes:= proc(a::realcons, Lim::realcons)

local

     a0:= `if`(a::prime, a, nextprime(a)),

     b:= nextprime(a0), n, r;

          for n while b <= Lim do

          if b-a0 = 2 then r[n]:= [a0,b] end if;

          (a0,b):= (b,nextprime(a0))

     end do;

     convert(r, list)

end proc:

The procedure  IntegerPoints1  solves the same problem  as  IntegerPoints , has the same input parameters and the same output. But it is much faster and more reliable than  IntegerPoints   IntegerPoints1  is based on brute force method  and doesn't use  LinearMultivariateSystem  or  isolve .

IntegerPoints1 := proc (SN::{list, set}, Var::list)

local SN1, sn, n, i, p, q, xl, xr, Xl, Xr, X, T, k, t, S;

uses combinat;

SN1 := SN;

for sn in SN1 do if type(sn, `<`) then SN1 := subs(sn = (`<=`(op(sn))), SN1) fi; od;

 n := nops(Var);

for i to n do

p := simplex[minimize](Var[i], SN1); q := simplex[maximize](Var[i], SN1);

if p = {} or q = {} then return {} else

if p = NULL or q = NULL then error "The region should be bounded" else

xl[i] := eval(Var[i], p);

xr[i] := eval(Var[i], q) fi; fi; od;

Xl := ceil~(convert(xl, list)); Xr := floor~(convert(xr, list));

X := [seq([$ Xl[i] .. Xr[i]], i = 1 .. n)];

T := cartprod(X); k := 0;

while not T[finished] do

t := T[nextvalue]();

if convert(eval(SN, Var=~t), `and`) then

k := k+1; S[k] := t fi; od;

S := convert(S, set);

if type(S, set(list)) then S else {} fi;

end proc:

 

Markiyan's example :

with(PolyhedralSets): with(ExampleSets):

rs := RandomSolid(6, 4):

#  the solid  rs  is increased 5 times 

IntegerPoints1(eval(Relations(rs), Coordinates(rs)=~(`/`~(Coordinates(rs), 5))), Coordinates(rs));

nops(%);

 

 

Thanks  Markiyan  for helpful criticisms and  vv  for the constructive suggestions that have been used in the procedure.

 

IntergerPoints1.mw

 

 

 

@vv  Thank you for your constructive suggestions. Using them  I'll try to rewrite the procedure  IntegerPoints  without   LinearMultivariateSystem  command.

@Markiyan Hirnyk  Thank you for your interest. The reason for the error is  the built-in command  SolveTools[Inequality][LinearMultivariateSystem] which was used in the procedure  IntegerPoints . See the simple example with the same bug:

SolveTools[Inequality][LinearMultivariateSystem]([x[1] > 0, x[2] > 0, x[1]+x[2] < 3], [x[1], x[2]]);

    Error, (in Utilities:-SimpleAnd) invalid input: a string/name list is expected for sort method `lexorder`

 

If you do not use indexed variables, all right:

SolveTools[Inequality][LinearMultivariateSystem]([x1 > 0, x2 > 0, x1+x2 < 3], [x1, x2]);

                             {[{0 < x1, x1 < 3}, {0 < x2, x2 < 3-x1}]}

 

 

@litun  If you are interested in only one real root  in the appropriate range  for each  , use the  fsolve  command.

Details in  Roots1.mw

@vv  

restart;

rsolve(f(n+1)=f(n)+c, f(n));

                                                          f(0)-c+c*(n+1)

@mskalsi  Perhaps this is a bug. We see that the result depends on name of a variable:

simplify(diff(u(x,t), x,t), {diff(u(x,t), x) = 0});

simplify(diff(u(x,y), x,y), {diff(u(x,y), x) = 0});

                                  diff(u(x,t),t,x)

                                           0

 

@Markiyan Hirnyk  The code works under these refinements.

@Markiyan Hirnyk  

simplify(diff(u, y), {diff(u, x) = 0});

                                 0

You wrote  "another root  that i known, are : 0.165237712988657e-1    and     .103583272213766    and    .290071279318035"

See

plot(g, x = 0 .. .4);

                                     

 

 

 

@vv  You wrote  "In the "exterior" of this hyperbola, the solution is on a curve (also a hyperbola)". But 

{x=(-4*y-6)/(y+2), y=y}  is the same hyperbola. 

@nm  When the  unapply  command is called, there is an immediate calculation, and if  ->  command is called, then the calculation is delayed.

Here is an example:

f:=unapply(int(x^2, x=0..a),a);

g:=a->int(x^2, x=0..a);

                          

 

f(2);

g(2);

                                       

Addition: Here an example where the first command works, and the second command does not work: 

f:=unapply(rsolve({u(n+1)=u(n)+2, u(1)=1}, u(n)), n);

g:=n->rsolve({u(n+1)=u(n)+2, u(1)=1}, u(n));

f(3);

g(3);

 

The reason is obvious - the premature calculation.

 

 

@Bendesarts  Here is the correction my previous plotting (I did not notice that the lines at the zeros of the function to be built only in the points of increasing of the function) . I also added vertical lines at points of extreme.

restart;

v := t->H*sin(w*t):

L := 0.080: H := 0.020: Vf := 0.3: w := 10:

zeros1 := sort([RootFinding[Analytic](v(t), t, re = .5 .. 2, im = -1 .. 1)]):
zeros10 := select(t->D(v)(t)>0, zeros1);

zeros2 := sort([RootFinding[Analytic]((D(v))(t), t, re = .5 .. 2, im = -1 .. 1)]):
zeros20 := selectremove(t->D[1, 1](v)(t) < 0, zeros2);

plot([v(t), seq([zeros10[k], t, t = -0.01 .. 0.01], k = 1 .. 3), seq([zeros20[1, k], y, y = v(zeros20[1, k])-0.01 .. v(zeros20[1, k])+0.01], k = 1 .. 2), seq([zeros20[2, k], y, y = v(zeros20[2, k])-0.01 .. v(zeros20[2, k])+0.01], k = 1 .. 2)], t = 0.5 .. 2, color = [black, yellow$3, red$2, blue$2], linestyle = [1, 3$7], thickness = [1, 2$7]);

     

 

 

 

@Rouben Rostamian   Examples in the help and my own experiments with  Basis  command confirmed it (remember that the initial rows are assumed to be linearly independent). Of course if you need to be sure absolutely, it's necessary to study the source code of  Basis  procedure.

Addition: of course, the addition of linearly independent unit vectors to the initial rows can be done without  Basis command, if first we apply  LinearAlgebra[GaussianElimination]  or  LinearAlgebra[ReducedRowEchelonForm]  commands.

 

First 85 86 87 88 89 90 91 Last Page 87 of 134