Preben Alsholm

MaplePrimes Activity


These are answers submitted by Preben Alsholm

Since you can look up all the definitions required, it would be helpful if you could point out which result is wrong.

restart;
L:=[sqrt(-3)^1, sqrt(-3)^7]; # Output L := [sqrt(3)*I, -27*I*sqrt(3)]
?type/radnumext
eval(`type/radnumext`);
?type/radext
interface(verboseproc=3);
eval(`type/radext`);
?type/radical
?radnum
eval(`type/radnum`);

Continuing with L:

L := [sqrt(3)*I, -27*I*sqrt(3)]
LL:=convert~(L,list);
###
seq(type~(LL[i],radnumext),i=1..2);
map(indets, L, radnumext);
###
seq(type~(LL[i],radext),i=1..2);
map(indets, L, radext);
###
seq(type~(LL[i],radical),i=1..2);
map(indets, L, radical);

One might be surprised that converting -27*I*sqrt(3) to a list gives only 2 elements.
The reason is probably the definition of I as Complex(1). See ? I.
 

L[2];
nops(%);
op(1,L[2]);
op(2,L[2]);
Complex(-27);
addressof(op(1,L[2]));
addressof(Complex(-27));## The same address
 

Continuing a little further:
 

addressof(L[2]);
addressof(Complex(-27*sqrt(3))); # Not the same as L[2]
simplify(Complex(-27*sqrt(3)));
addressof(%); # The same as L[2]

 

You could rename all this way:
 

restart;
S1:=singular(1/sin(x),x);                    
S2:=singular(x/sin(x),x);
S3:=singular(x^2/sin(x),x);
indets(`union`(S1,S2,S3),`local`)=~_Z; 
assign(%);
`union`(S1,S2,S3); 
 # result  {x = Pi*_Z}

 

Try this:
 

plot([cos(t), sin(t), t = 0 .. 2*Pi*10000],adaptive=false);
plot([cos(t), sin(t), t = 0 .. 2*Pi*10000],adaptive=false,style=point);
plot([cos(t), sin(t), t = 0 .. 2*Pi*10000],style=point);

The result from the first connects the points (those seen when using style=point, and adaptive = false).
The third generates many more points.
Try increasing the number of points in the first:
 

plot([cos(t), sin(t), t = 0 .. 2*Pi*10000],adaptive=false,numpoints=500);

With numpoints=500 you get close to seeing what is going on.

PS. So how many points are chosen by the last plot?
You can find out by doing:

A:=plot([cos(t), sin(t), t = 0 .. 2*Pi*10000]);
op(1,A); #5445 points (only)

To get the same data you can also do:

plottools:-getdata(A);

PPS.  I'm very fond of odeplot. Here is a plot made by odeplot:

restart;
ode:=diff(x(t),t,t)+x(t)=0;
sol:=dsolve({ode,x(0)=1,D(x)(0)=0}); # first argument to you plot
-diff(sol,t); # second argument to your plot
res:=dsolve({ode,x(0)=1,D(x)(0)=0},numeric,maxfun=0); # Numerical solution
plots:-odeplot(res,[x(t),-diff(x(t),t)],0..2*Pi);
plots:-odeplot(res,[x(t),-diff(x(t),t)],0..2*Pi*10000,numpoints=10000);

Another version that doesn't involve using an ode particular yo the plot you want to make:
 

restart;
sys:={diff(x(t),t)=0,x(0)=0,diff(y(t),t)=0,y(0)=0};
dsolve(sys); # As intended
resS:=dsolve(sys,numeric,maxfun=10^6);
plots:-odeplot(resS,[x(t)+cos(t),y(t)+sin(t)],0..2*Pi,labels=["",""]);
plots:-odeplot(resS,[x(t)+cos(t),y(t)+sin(t)],0..2*Pi*10000,numpoints=10000,labels=["",""]);

 

The problem is the expansion that occurs.
Here is an ad hoc solution:
 

restart;
integrand:=(2*x^2022+1)/(x^2023+x);

num:=numer(integrand);
den:=denom(integrand);
igt:=(num-x^2022)/den + x^2022/den;
map(int,igt,x);

Or following Axel's lead:
 

integrand2:=(2*x^n+1)/(x^m+x);
int(integrand2,x);
eval(%,{n=2022,m=2023});

Generalizing further:
 

integrand3:=(a*x^n+b)/(c*x^m+d*x);
int(integrand3,x) assuming a>0,b>0,c>0,d>0;
eval(%,{a=2,b=1,c=1,d=1,n=2022,m=2023});

 

Instead of the version given by nm, you could do:
 

f := unapply(piecewise(0 < x and x < a, k1, a < x and x < b, k2), a,x);

simplify(f(a,x)) assuming 0 < a, 0 < x and x < a;
simplify(f(b,y)) assuming 0 < b, 0 < y and y < b;nn

Both return k1.
The difference between the two versions of simplify with assuming/assume, is that in your version any assumptions are placed on the expression before any evaluation takes place. But then your function fa(x) doesn't see a inside the procedure fa, and so no assumption is therefore placed on a.
In the version given by nm fa(x) is evaluated first and assumptions are made.
In my version above the assumptions are placed on the arguments given right away, in my two examples a,x and b,y.

Change EQ3 to:
 

EQ3 := c[11] + c[12] + b^2*Q[0, 1]*sin(n*Pi*y[0, 1]/b)*(exp(-n*Pi*x[0, 1]/b) - exp(n*Pi*x[0, 1]/b))/(n*Pi) = lambda* (c[21] + c[22]);

It was:
 

EQ3 := c[11] + c[12] + b^2*Q[0, 1]*sin(n*Pi*y[0, 1]/b)*(exp(-n*Pi*x[0, 1]/b) - exp(n*Pi*x[0, 1]/b))/(n*Pi) = lambda . (c[21] + c[22]);  
# Notice the right hand side. The dot should be *

 

If you remove eval from the definition of h then you get:

f();
g says: z evaluates to 2.
h says: z evaluates to z.
 

You set z:=2;  in f and write h('z');

Inside the procedure f this evaluates to h(z) only, because of the unevaluation quotes.

That doesn't mean that h is being handed a variable without any value. It just need evaluation, which it receives in your version of h.

Consider this simple example:
 

restart;
p:=proc() local z; z:=2; 'z' end proc;
p(); # z
%; # Now full evaluation to 2

 

I think that applyrule isn't meant to be all that ambitious. A quote from the help page for applyrule:

"It is more powerful than the command subs, but does not do mathematical transformations as algsubs does."

The only thing I could come up with is this:
 

restart;
rule1:=A::`&+`(anything,anything)=bbbb;
applyrule(rule1,[a+b,c+d,a+b+c]);
rule2:=A::`&+`(anything,anything)=''`*`(op(A))'';  # Notice double unevaluation quotes
applyrule(rule2,[a+b,c+d,a+b+c]);

Note: If you change the type in 'the_rule" to symbol, you get a+b:
 

restart;

the_rule:=A::symbol+B::symbol=A*B;

applyrule(the_rule,a+b); # result a+b, NOT a*b

Now it gets weird because if you change to 'name' then you get what you want a*b:
 

restart;

the_rule:=A::name+B::name=A*B;

applyrule(the_rule,a+b); # Result a*b

So my conclusion is that applyrule is rather limited and when used outside of its intended use, it gives you strange results. Maybe an example of garbage in, garbage out.
The procedure has a copyright from 2005.

The help pages' examples are really the same and the results are most often too.
Here is one where they differ:
 

subsindets( [sin( x ), cos( y ), tan(z)], 'symbol', y -> y + Pi );
%;
evalindets( [sin( x ), cos( y ), tan(z)], 'symbol', y -> y + Pi );

If in the first line subsindets is replaced by subsindets[eval] the output is the same as from evalindets.

I notice that the equation eqt considered as giving x implicitly as a function of t solves the well-studied pendulum equation:
 

diff(x(t), t, t) + k*sin(x(t)) =0;

For information you could go to
https://en.wikipedia.org/wiki/Pendulum_(mechanics)

So do the solving numerically:
 

restart;
ode := diff(x(t), t, t)+ k*sin(x(t));
res:=dsolve({ode,x(0)=a,D(x)(0)=0},numeric,parameters=[a,k]);
res(parameters=[1,.3]); #Setting parameters
plots:-odeplot(res,[t,x(t)],-20..20);
res(parameters=[1,1.5]); #Setting new parameters
plots:-odeplot(res,[t,x(t)],-20..20);

Be careful: If you reexecute the first plotting command then the most recent parameters are used.
You can, however, save the plots as in this version:
 

restart;
ode := diff(x(t), t, t)+ k*sin(x(t));
res:=dsolve({ode,x(0)=a,D(x)(0)=0},numeric,parameters=[a,k]);
res(parameters=[1,.3]); #Setting parameters
plots:-odeplot(res,[t,x(t)],-20..20,thickness=3); p1:=%:
res(parameters=[1,1.5]); #Setting new parameters
plots:-odeplot(res,[t,x(t)],-20..20,color=blue); p2:=%:
plots:-display(p1,p2);

Using the file provided I tried selecting the cosine expression. Then right clicked on that and chose convert to 1D-Math input.
That worked. The same worked on sqrt(4).

I don't know what you mean by wanting to create a vector x.
But in order to find out you could look at this code:
 

restart;
n:=3:
Theta:=<0.2,0.3,1.5>;
A:=<2,6,3>;
F:=<10,4,7>;
f:=unapply(add(A[i]*cos(F[i]*x+Theta[i]),i=1..n),x);
f(.9);
plot(f(x),x=-3..10);

Guessing: Could this continuation be it?
 

N:=10000:
X:=Vector(N,i->0.001*i);
Y:=f~(X);
plot(X,Y); # Just for illustration

 

I made som changes:
 

restart;
pde:=diff(<u1(x,t),u2(x, t)>, t) = Matrix([[0, mu*k^2/2], [2*A^2 - mu*k^2/2, 0]]).<u1(x,t),u2(x, t)>;
pdsolve(pde);

 

You could use subs as in this code:
 

A:=Int(r^2, m);
B:=subs(m=(m=a..b),A);

 

On my Maple 2022.2 I just added simplify:
 

restart;
g := piecewise((1/2)*t < 1/2, 0, (1/2)*t < 3/2, 1, 0)*piecewise(z/t < 1, 0, z/t < 2, 10080-60480*z/t+156240*z^2/t^2-226800*z^3/t^3+202230*z^4/t^4-113400*z^5/t^5+39060*z^6/t^6-7560*z^7/t^7+630*z^8/t^8, 0)/t;

Int(g, t=1..3);
value(%); 
simplify(%);

That brought an explicit answer. I don't have Maple 2015 on the computer I have available here, but it works on Maple 2021.2 too.

4 5 6 7 8 9 10 Last Page 6 of 160