vv

2053 Reputation

9 Badges

1 years, 182 days

MaplePrimes Activity


These are answers submitted by vv

I have changed the interval 0..2*Pi where a Lisajous curve  x=A cos(m t), y=B sin(n t) is considered in order to reflect the geometrical (rather than analytical) multiplicity of the points.

DblPoints:=proc(M::posint,N::posint,A::positive:=1,B::positive:=1,{DP::name:=0})
local t,u,tu, a,b,p,P,par,eq, R:=NULL, S:=0,L:=2*Pi, m:=M/igcd(M,N),n:=N/igcd(M,N);
if type(m,even) then S:=Pi/2;L:=Pi fi;
par:=A*cos(m*t),B*sin(n*t):
eq:={m*(t+u) = m*t*p + 2*a*Pi, n*(t+u) = (-1)^b*n*t + b*Pi}:
for a from 0 to 3*m do for b from 0 to 6*n do for p in {-1,1} do
  tu:=solve(eval(eq),{t,u});
  if tu<>NULL and is(eval(t,tu)>=S and eval(u,tu)>0 and eval(t+u,tu)<S+L)
  then R:=R,eval(t,tu)  fi  od od od:
P:={seq(eval([par]), t=[R])}; if DP<>0 then DP:=P fi;
plots:-display(plot(P,style=point,symbol=circle,symbolsize=20,color=blue),
               plot([par,t=S..S+L]),title=cat("m"=m,", n"=n,", dbl"=nops(P)));
end:

DblPoints(4,5,DP='dbls');

dbls;

DblPoints(5,4);

dblpoints:=proc(m::posint,n::posint,A,B)
local t,u,tu, a,b,p,DP,par,eq, R:=NULL;
par:=A*cos(m*t),B*sin(n*t):
eq:={m*(t+u) = m*t*p + 2*a*Pi, n*(t+u) = (-1)^b*n*t + b*Pi}:
for a in {seq(0..3*m)}  do
for b in {seq(0..6*n)} do
for p in {-1,1} do
tu:=solve(eval(eq),{t,u});
if tu <> NULL and not(type(eval(u,tu)/(2*Pi),integer)) then R:=R,eval(t,tu) fi
od od od:
R:=select( u -> is(u>=0 and u<2*Pi),{R}):
DP:={seq( eval([par]), t=R)};
print('num'=nops(DP),DP);
plots:-display( plot(DP, style=point,symbol=circle,symbolsize=24,color=blue),
                plot([par, t = 0 .. 2*Pi]));
end:

Works even for large m,n:
dblpoints(7,4,2,3);
 

Edit: corrected typo in code.

It is odd that  in  ImportMatrix(fn, source=csv)   a backslash inside a string is not seen as an escape character
but in ExportMatrix(fn, A,  target=csv),  a backslash is doubled;

Here is a procedure which seems to work when exporting matrices containing numbers and strings.

ExMa:=proc(fn::string, A::Matrix)
local i,L,Q, fd:=fopen(fn,WRITE,TEXT);
Q:=proc(u)
  if type(u,string) then return cat( "\"", u, "\"," )
  else cat(convert(u,string),"," )  fi
end;
for i to op([1,1],A) do
  L:=cat( seq(Q(u), u=A[i]) );
  writeline(fd,L[1..-2])
od;
close(fd);
end;

 

'maximize'(f) inside the plot command  computes    max {f: t in R}   for a given m  in the interval 1..10.

In Maple this can be expressed:

F:= m -> maximize( cos(2*t/m) + cos(2*(t+5)/m), t );
plot(F, 1..10);

Note that it's not difficult to see that  F(m) = 2*abs(cos(5/m)).
So, the plot can be obtained directly:

plot( 2*abs(cos(5/m)), m=1..10 );

 

I think that the random behavior is due to the following fact.
For some reason, the order of the terms in a symbolic sum is not deterministic (in some situations); so, because the addition of floats is not associative the result will depend on this order.

add(sin(k),k=1..15);
   sin(1)+sin(2)+sin(3)+sin(4)+sin(5)+sin(6)+sin(7)+sin(8)+sin(9)+sin(10)+sin(11)+sin(12)+sin(13)+sin(14)+sin(15)

add(sin(k),k=1..25);
  sin(19)+sin(20)+sin(21)+sin(22)+sin(23)+sin(24)+sin(25)+sin(2)+sin(3)+sin(4)+sin(5)+sin(6)
  +sin(7)+sin(8)+sin(9)+sin(10)+sin(11)+sin(12)+sin(13)+sin(14)+sin(15)+sin(16)+sin(17)+sin(18)+sin(1)

Note that the order is NOT always random; after a restart it happend that the 1..25 sum became ordered!

 

J:=proc(n::posint,k::posint)  # numbering 0..n-1
local N;
if n=1 then return 0 fi;
if n<k then return (J(n-1,k)+k) mod n fi;
N:= n-floor(n/k);
floor(k*((J(N,k)-(n mod k)) mod N)/(k-1))
end:

J(5,3);
      3

hterms:=proc(P, n::nonnegint, v::set(name):=indets(P))
  select(t->degree(t,v)=n, expand(P))
end proc:
P := (a^2 + 2)*(b^2 + 2)*(c^2 + 2):
hterms(P,4);

If you think that LambertW is to blame, it is very easy to get rid of it replacing in your relation

LambertW(x)=y   with  x = y*exp(y).

But probably the problem is that in your expression the rounding errors are too big. Note that if Digits is increased to 30 the plot is almost empty, so this could be the real situation.

Dr:=proc(P::depends(list(And(ratpoly(integer,Variables),Not(integer)))),Variables::list(symbol),DEvar::symbol,DEsuffix::string)

PS. Note that ratpoly means rational function (such as (x+1)/(x*y+2)), not polynomial.

 

It is enough to set

_EnvFormal:=true;

Note that without this, even sum(p^k, k=0..infinity) is not computed. Of course one may use assume on parameters (in order to have convergence) but there are too many of them and I understand that your series are formal.

convert(a, cot);

I'd recommend to start with these much simpler integrals and see what happens:

int(sqrt(x^4+1),x);
int(sqrt(x^4+1+x),x);
int(sqrt(x^4+1+sqrt(x^2+1)),x);

 

restart;
with(LinearAlgebra):
t:=time():
n:=1000:
A:=RandomMatrix(n,n,generator=rand(-10.0..10.0),shape=symmetric,datatype=float[8]):
V,Q:=Eigenvectors(A):
MV:=DiagonalMatrix(sqrt~(Vector(V,datatype=complex))):
B:=Q.MV.Q^*:
`||A-B^2||`=Norm(A-B^2);
'time'=time()-t;

                                           
             ||A-B^2|| = 4.49369731341387095 * 10^(-11)  
                         time = 26.021

 

The integral `f*g` is expressed with the Dirac "function" and some problems appear.
Just convert f to Heaviside and it will work.
You may insert after your f:=...

f:=unapply( convert(f(x),Heaviside), x );

(Note that `f*g`(x) will be much simpler!)

1 2 3 4 5 6 7 Last Page 1 of 28