Preben Alsholm

13663 Reputation

22 Badges

19 years, 344 days

MaplePrimes Activity


These are answers submitted by Preben Alsholm

I did it. In order to use it you have to agree to the terms of use.
Wanting to test it I agreed to the terms.  After the testing I took that back. That is possible in the same place.

If you want to avoid the weird looks of the definition ot totvol in your second run, use unapply instead of what you got:
 

totvol := unapply(Pi*0.4^2*ht^2*ht + 1/3*Pi*0.4^2*ht^2*2/3*ht,ht);

The output is simple:  totvol := ht -> 0.1955555556*Pi*ht^3

Illustrating vv's point I tried starting solutions at x=1 for several values of y(1) and plotting the results:
 

restart;
de1 := diff(y(x), x) = y(x)/x - 5^(-y(x)/x);
S:=seq(rhs(dsolve({de1,y(1)=k})),k=0..20);
plot([S],x=0..1);
plots:-display(seq(plot(S[k],x=0..1),k=1..21),insequence);# An animation

The animation is attached:

There seems to be a bug in int here. I changed pi into Pi.
#### NOTE The bug is fixed with Physics update 1717.

restart;
int(x^2,x=0..x); # Allowed in Maple these days
int(x^2,x=0..N); # Obviously OK
## Now the present case:
eq0:=int((1 - omega)^(k + 1), omega = 0 .. 1) = C*int((1 - sigma*sin(2*Pi*N))^k, N = 0 .. N);
simplify(eq0) assuming k::posint; # Surprising!!
A0:=rhs(eq0/C);
simplify(A0) assuming k::posint; # N

## Now don't allow yourself this double use: N upper limit as well as integration variable:
## The upper limit is now N as above but the variable of integration is x:
##
eq:=int((1 - omega)^(k + 1), omega = 0 .. 1) = C*int((1 - sigma*sin(2*Pi*x))^k, x = 0 .. N);
simplify(eq) assuming k::posint; # The integral still unevaluated
A:=rhs(%/C); # The integral
simplify(A) assuming k::posint,N::integer; # No change
############ 12 concrete k's 
L:=[seq](A,k=0..11):
L[1..4]; # Viewing 4 of the elements
L2:=simplify(L) assuming N::integer;
pols:=normal(L2/~N);
degree~(pols,sigma);

MaplePrimes24-04-04_int_bug.mw

Note added:
 

A0:=int((1 - sigma*sin(2*Pi*N))^k, N = 0 .. N);
simplify(A0) assuming k::posint; # N The bug
L:=[seq](A0,k=0..11):
L[1..5];
simplify(L) assuming N::integer;  #OK

Yet another note: simplify without assumptions returns N too:
 

simplify(A0);  # N

 

This works without any explicit reference to trig or exp:

restart;
combine(exp(sin(a)*cos(b))*exp(cos(a)*sin(b)));

Output exp(sin(a + b)).
This works in your simplify case:

simplify(16^(3/2));

Procedures can be indexed. Here is a conjured up simple example:

p:=proc(x) local idx; 
   if type(procname,'indexed') then 
     idx:=op(procname);
     x,idx
   else
     x   
   end if
end proc;
p(4);
p[abc](4);

 

Clearly if z is unassigned temp_proc(z, 2); will produce the error you see. It cannot determine if z > 2.
Both of the following work:

plot('temp_proc(z,2)',z=-2..3);# Notice the unevaluation quotes ' '
plot(rcurry(temp_proc,2),-2..3);# A procedural version: no z anywhere

To understand rcurry try rcurry(f,2);
###############
Note added:

You could change your procedure so that it returns unevaluated if it doesn't receive numerical input:
 

restart;
fun := piecewise(x+y > 1, (x+y)^2, x-y);


temp_proc := proc(x, y) if not [x,y]::list(realcons) then return 'procname(_passed)' end if;
local out, ind:

#ind := 9: Not used

if x > y then ind := 1 else ind := 0 end if; 

if ind = 1 then out := eval(5*fun, {:-x=x, :-y=y}) else out := eval(-5*fun, {:-x=x, :-y=y}) end if:

return(out);
end proc:

temp_proc(z,2);
temp_proc(1,-2);
plot(temp_proc(z,2),z=-2..3);

 

You can plot and integrate, but I don't see how you can use dsolve with this object.

restart;
M := Array(1 .. 10, 1 .. 2):

for i to 10 do
    M[i, 1] := i;
    M[i, 2] := 3*i;
end do:

M;
Mt := Interpolation:-LinearInterpolation(M);

Mt(3/2);
plot(Mt(t),t=0..10);
int(Mt,0..10,numeric);

 

The problem is that fun is defined outside the procedure. The x and y there are global variables and has nothing to do with the x and y appearing as the parameters in the procedure.
The remedy is simple:
 

restart;
temp_proc := proc(x, y)
local out1, out2, out3, fun:
fun := x^2+y^2;
if x > 0 then out1 := fun; out2 := 2*fun; out3 := k*fun;
elif x <= 0 then out1 := fun; out2 := -2*fun; out3 := -k*fun;
end if:

return(out1, out2, out3);
end proc:

xt := -1: yt := 2:
out1_fin := temp_proc(xt, yt)[1];
out2_fin := temp_proc(xt, yt)[2];
out3_fin := temp_proc(xt, yt)[3];

In the procedure k is treated as global, so out3_fin depends on whether or not k has been assigned a value outside.

maplemint(temp_proc);


 

I wouldn't use DEplot myself. Here is what I would do:

restart;
with(plots):
sys := {diff(x(t), t) = y(t), diff(y(t), t) = -x(t) - 1/2*y(t)}
ics:={x(0) = 1, y(0) = 0};
sol:=dsolve(sys union ics);
solx,soly:=op(subs(sol,[x(t),y(t)]));
plot([solx,soly,t=0..15],labels=[x,y],color=blue);
animate(plot,[[solx,soly,t=0..T],labels=[x,y],color=red,thickness=2],T=0..20);
###################################
## A nonlinear system. We use numeric solution here.
sys2 := {diff(x(t), t) = y(t), diff(y(t), t) = -x(t) - 1/2*y(t)^2}
ics:={x(0) = 1, y(0) = 0};
res:=dsolve(sys2 union ics,numeric);
odeplot(res,[x(t),y(t)],0..200,numpoints=10000,color="DarkGray");
odeplot(res,[x(t),y(t)],0..200,numpoints=10000,color="SkyBlue",frames=50);

MaplePrimes24-04-01_spiral.mw

 

This is a bug.
 

restart;
A := abs(x*Heaviside(x) + x*Heaviside(-x));
plot(A,x=-1..1); #OK
int(A,x=-1..1); # Wrong: should be 1
int(A,x=-1..1,numeric); # 1.000000000
int(A,x=-1..1,method=_RETURNVERBOSE);
int(A,x=-1..1,method=_VERIFYFLOAT);
## Workaround:
B:= x*Heaviside(x) + x*Heaviside(-x);
BP:=convert(B,piecewise);
plot(BP,x=-1..1);
plot(abs(BP),x=-1..1);
int(abs(BP),x=-1..1); # 1

I shall submit a bug report.

In Maple 2024 use adaptive=true, or simply adaptive.
 

res := t^3 - 3*t^2*sqrt(t^2*(12*sqrt(2)*ln(t) + 9*ln(t)^2 + 8)^(1/3))*ln(t)/(12*sqrt(2)*ln(t) + 9*ln(t)^2 + 8)^(2/3) - 2*t^2*sqrt(t^2*(12*sqrt(2)*ln(t) + 9*ln(t)^2 + 8)^(1/3))*sqrt(2)/(12*sqrt(2)*ln(t) + 9*ln(t)^2 + 8)^(2/3);

evalf(eval(res,t=-5));
plot(res,t=-5..1,adaptive,thickness=3);

 

Inspired by Rouben and using his example:
 

restart;
plot([10 + sin(x),0], x=3*Pi..4*Pi);
plot([10 + sin(x),0], x=3*Pi..4*Pi,color=[blue,white],thickness=[3,1]);
plot([-2 + sin(x),0], x=3*Pi..4*Pi);
plot([-2 + sin(x),0], x=3*Pi..4*Pi,color=[blue,white],thickness=[3,1]);
plot([sin(x),0], x=Pi..4*Pi,color=[blue,white],thickness=[3,1]);

 

I'm not sure what you mean by "Kronecker not recognized".
The issue seems to be the following:
 

restart;
A:=Int(
         Sum(p__n*exp(-I*theta)^n, n = 0 .. infinity)*Sum(p__m*exp(theta*I)^m, m = 0 .. infinity), 
       theta = 0 .. 2*Pi);
eval(A,Int=int); # 0 Wrong!
# Counter example:
B:=subs({p__n=exp(-n),p__m=exp(-m)},A); # Don't use eval instead of subs
value(B); #  2*Pi*exp(2)/(exp(2) - 1)

 

A very useful feature of display is overrideoptions:
 

restart;
pt:=plottools:-line([1,2], [3,4],color=red,thickness=2,linestyle=dash); 
plots:-display(pt);
plots:-display(pt,overrideoptions,linestyle=1,thickness=5,color=blue);

restart;
with(IntegrationTools):
J1 := Int(h(x), x=-infinity..a) - Int(h(x), x=-infinity..b);
Ja:=Int(h(x), x=-infinity..a);
Jb:=Int(h(x), x=-infinity..b);
# Case 1: a>b.
Sab:=Split(Ja,b) assuming a>b;
Combine(Sab-Jb);
# Case 2: a<b. 
Sba:=Split(Jb,a) assuming a<b;
Combine(Ja-(Sba)) assuming a<b;
simplify(%);

MaplePrimes24-02-27_IntegrationTools_Combine.mw

NOTE: You don't need the assumption at the end, but it doesn't hurt.
You could add Flip(%); after simplify(%);
Then the results from both cases look the same.

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