Kitonum

21825 Reputation

26 Badges

17 years, 218 days

MaplePrimes Activity


These are answers submitted by Kitonum

As far as I know, the  is  command attempts to syntactically confirm or disprove the equality presented to it using various simplifying procedures. If it is unable to do so, it should return  FAIL. Therefore, output  false  as result of  is(Q1=Pi/exp(1))  should be considered as  a bug. Sometimes it is useful to help it a little to obtain the result. Below are some examples of the  is command in action.
 

restart;
Q1 := int(sin(Pi*x)/(x^x*(1-x)^(1-x)), x = 0 .. 1); 
seq(is(evalf[10*k](Q1) = evalf[10*k](Pi/exp(1))), k = 1 .. 10);
is(Pi = 3.14); 
is(evalf(Pi) = 3.14); 
is(evalf[3](Pi) = 3.14); 
eq := sqrt(x+2*sqrt(-1+x)) = sqrt(-1+x)+1; 
is(eq) assuming x >= 1; 
is(eq^2) assuming x >= 1;

              


When using the  identify command, the expression must be evaluated with sufficient precision. Often, 10 digits (the default) is insufficient, but requiring 100 digits is probably overkill. Typically, 15-20 digits are sufficient.

identify(evalf(Q1));
identify(evalf[15](Q1));
identify(evalf[20](Q1));

                          

 

 

I completely rewrote this code to improve the visual clarity and informativeness. Everything related to the cosine is in red, and everything related to the sine is in blue. Furthermore, the red segment equal to the cosine value is also plotted not only horizontally but also vertically, so that all the dash-lines are parallel to the horizontal axis.

restart;
OneFrame:=proc(t)
local h, r, Circle, L1, L2, L3, L4, L5, L6, L7, L8, P1, P2, P3, P4, P5, P6, Curves, Arc, T;
uses plots, plottools;
h:=-1.3; r:=0.04;
Circle:=circle([h,0], view=[h-1.2..h+1,-1.4..1.4], axes=none);
L1:=line([h,-1.5],[h,1.5]); L2:=line([h+cos(t),0],[h,cos(t)], linestyle=2); L3:=line([h,0],[h+cos(t),0], color=red, thickness=3); L4:=line([h,cos(t)],[h,0], color=red, thickness=3);
L5:=line([h,0],[h+cos(t),sin(t)]);L6:=line([h+cos(t),0],[h+cos(t),sin(t)], color=blue, thickness=3);
L6:=line([h,cos(t)],[t,cos(t)], linestyle=3, thickness=0);
L7:=line([h+cos(t),sin(t)],[t,sin(t)], linestyle=3, thickness=0);
L8:=line([h+cos(t),sin(t)],[h+cos(t),0], thickness=3, color=blue); 
P1:=disk([h,0],r); P2:=disk([h+cos(t),sin(t)],r); P3:=disk(
[h+cos(t),0],r, color=red); P4:=disk([h,cos(t)],r, color=red);
P5:=disk([t,sin(t)],r, color=blue);
P6:=disk([t,cos(t)(t)],r, color=red);
Curves:=plot([sin(x),cos(x)], x=0..t, color=[blue,red], thickness=2, view=[0..2*Pi,-1.4..1.4], tickmarks = [[seq(Pi/2*k=k*Pi/2, k=1..4)], default]);
Arc:=arc([h,0],0.3, 0..t);
T:=textplot([[0.2*cos(t/2)+h,0.2*sin(t/2),"t"],[t,cos(t),typeset(cat("(","t",",","cos(t)",")")), align=[above,right], color=red],[t,sin(t),typeset(cat("(","t",",","sin(t)",")")), align=[above,right], color=blue]], font=[times,14]);
display(Circle, L1, L2, L3, L6, L4, L5, L6, L7, L8, P1, P2, P3, P4, P5, P6, Curves, Arc, T, scaling=constrained, view=[h-1..6.5,-1.4..1.4]);
end proc:

plots:-animate(OneFrame, [t], t=0..2*Pi, frames=120, size=[1000,300], paraminfo=false);

         


cos_sin.mw

If we're solving this equation in the real domain, it's natural to use assumptions that ensure non-negativity under the root sign in the original equation, i.e.  x>-1  and  x<=1 . We also use the condition that  arcsech(x)  takes real values, i.e.  x>0  and  x<=1 . This ensures that everything is solved quickly and correctly:

restart;
ode:=-x*sqrt((1 - x)/(x + 1))*(x + 1)*arcsech(x)*diff(y(x), x)*exp(y(x)/arcsech(x) + exp(y(x)/arcsech(x))) - y(x)*exp(y(x)/arcsech(x) + exp(y(x)/arcsech(x))) + 2*x*sqrt((1 - x)/(x + 1))*(x + 1)*arcsech(x)^2 = 0;
convert(arcsech(x), ln);
Cond:=solve({(1 - x)/(x + 1)>=0, op(1,%)>0}, x)[];
sol:=CodeTools:-Usage(dsolve(ode)) assuming Cond;
odetest(sol, ode) assuming Cond;

       

Use the  unapply  command  instead  of  the  ->  notation  to define the  F  function:

restart;
F:=x-> (x^4+3*x^3-3*x^2-2*x-24)/(x^4-4*x^3-13*x^2+62*x-56);
u:=unapply(piecewise(x=-4, limit(F(x), x=-4), true, F(x) ), x);
u(-4);

                

The help for the  solve  command states that it may not find all roots, but using additional options  explicit  and  allsolutions  allows you to explicitly find all roots.
Regarding the  PDEtools:-Solve  command, the help does not state that it may not find all roots. Using some additional options listed in the help does not produce any new roots beyond the one already found  x=1 .  I use Maple 2018.2 .

restart;
f:=x->(x^2+3*x-4)*cos(x^2+3*x-5);
PDEtools:-Solve({f(x)=0,0<x,x<2}, x, explicit, allsolutions, solver =solve);
solve({f(x)=0,0<x,x<2},x, explicit, allsolutions);

       

Curve   consists of two branches located on opposite sides of the vertical asymptote  x=1 . The local maximum point is  (-1, -1) . However, there are infinitely many circles that are tangent to curve   at this point. From this family of circles, we find a single circle that is also tangent to the second branch of this curve.

restart;
f:=x->x+2+4/(x-1):
solve(D(f)(x)=0);
x0:=select(x->(D@@2)(f)(x)<0, [%])[];
y0:=f(x0);
Eq:=(x-x0)^2+(y-(y0+R))^2=R^2;
g:=unapply(solve(Eq, y)[1], x);
sol:=solve({f(x)=g(x),D(f)(x)=D(g)(x),y=f(x),R>0}, {x,y,R}, explicit);
R:=eval(R, sol[2]);
P1:=plot(x+2+4/(x-1), x=-6..6, color=blue, discont):
P2:=plottools:-circle([x0,y0+R],R, color=red):
P3:=plottools:-disk([x0,y0], 0.1, color=red):
P4:=plottools:-disk(eval([x,y],sol[2]), 0.1, color=red):
plots:-display(P1,P2,P3,P4, scaling=constrained, view=[-6..6,-4..10], size=[500,500]);

         

Circle.mw

Here is my attempt:

restart;
Colors:=[seq(op(["LightBlue","Indigo","Violet","Red","Orange","Yellow","Green"]),n=1..14)]:

P:=proc(n)
uses plots, plottools;
display(rotate(plot([x^(1+0.1*(n-1)),x^(1/(1+0.1*(n-1)))], x=0..1, thickness=5, color=Colors[round(n)], transparency=0.4),Pi*n/98, [0.5,0.5]));
end proc:

plots:-animate(P,[n],n=1..98, frames=98, trace=[$1..98], axes=none, size=[700,700], paraminfo=false);

                 

restart;
A:=Matrix([[1,2], [3,4]]);
ListTools:-Search(3, A);

                                      

See the post  https://mapleprimes.com/posts/202222-Contour-Curves-With-Labels  for this.

Your example:

f:=(11 - x - y)^2 + (1 + x + 10*y - x*y)^2:
ContoursWithLabels(f, 0 .. 20, 0 .. 15, 10,[color=black, thickness=2,size=[800,600]], Coloring = [colorstyle = HUE, colorscheme = ["White", "Red"], style = surface]);

              

If you use a procedure instead of an expression to plot a graph (that is  instead of  g(x) ), then you don't need to use quotation marks. Numpoints and adaptive options are also useful for plotting your graph. The default  numpoints=200 , but Maple actually uses many more points because the function values ​​change sharply at close points. To disable the added points, we must use  adaptive=false  (by default  adaptive=true ).

restart;
with(RandomTools):
g := x -> Generate(float(range = 0 .. x)):

plot(g, 1 .. 50, adaptive=false, size=[700,700]); # by 200 points

plot(g, 1 .. 50, numpoints=50, adaptive=false, size=[700,700]); # by 50 points

     

        

 


 

Download plot.mw

For some reason, the symbol   \n  for creating multiple lines of text in legends doesn't work. The only solution was adding indents at the beginning and end:

restart;
        
f:=x->x^3-x^2+1;
g:=x->6-2*x-x^2;
the_legend:=[typeset("     ","f(x) = ", f(x),"     "), typeset("      ","g(x) = ",g(x),"     ")]:
plots[setoptions](font=[TIMES,16], labelfont=[TIMES,18]):
the_title:="Plot of f(x) and g(x)":
plot([f(x),g(x)],x=-5..5,
     'gridlines',
     'color'=['red','blue'],
    legend=the_legend,
     'legendstyle'=['location'='bottom'],
     'axes'='normal',
     'title'=the_title,  
     'scaling'='unconstrained');
 

proc (x) options operator, arrow; x^3-x^2+1 end proc

 

proc (x) options operator, arrow; 6-2*x-x^2 end proc

 

 
 

 

Download legend.mw

The problem has infinitely many solutions depending on 2 parameters  x1  and  x2 . Below we find one solution for the values  x1=0 , x2=5 .

restart;
P:=x->x^4+a*x^3+b*x^2+c*x+d:
sys:={P(1)=10,P(2)=20,P(3)=30,(P(x1)+P(x2))/10=2026};
sol:=solve(sys);
P:=unapply(eval(P(x), sol), x):
P:=unapply(eval(P(x), [x1=0,x2=5]), x);
seq(P(x), x=[1,2,3]), (P(0)+P(5))/10;  # Check

               

Addition. It is possible to find two values  x1  and  x2  ​​(not the only way) such that all the coefficients of the polynomial  P(x)  are integers. For example, if we take  x1 = 2  and  x2 = 8 , we obtain a polynomial  P(x) = x^4 + 82*x^3 - 517*x^2 + 972*x - 528  for which all conditions are satisfied.

 

I think the reason is in the design of the  simplify  command. When you apply this command to an equality, Maple automatically applies it separately to the left and right sides of the equality. But obviously  1/A<>1  and x/A<>x . But on the other hand, Maple understands that equality  1/A = x/A  implies equality x=1 :

restart;
is(1/A = x/A implies x=1) assuming A<>0;

                                 true

Another example:

simplify(sqrt(x^2)=sqrt(1-cos(x)^2)) assuming x<-Pi/2, x>-Pi;
is(% implies x=sin(x));

                              -x = -sin(x)
                                  true

I don't know if Maple has a command that simplifies the equation itself, i.e. tries to reduce it to some equivalent equation that has a simpler form.

nm's  method can be generalized to expressions analogous to polynomials. The  parseTerms  procedure does this:

restart;
parseTerms:=proc(expr::{`+`,`*`,symbol})	
local P;
P:=t->[coeffs(t),map(X->`if`(X::`^`,[op(1,X),op(-1,X)],`if`(X::symbol,[X,1],NULL)),[op(t)])]; 
if expr::`*` then return P(expr) else
P~([op(expr)]) fi;
end proc:


Examples of use:

expr:=3*u*a^2*b^3*c^(m+1)*d^t:
parseTerms(expr);

                   

expr:=3*u*a^2*b^3*c^(m+1)*d^t - 4*u*a^2*b^3*c^(m+1)*d^t*1/e^2;
parseTerms(expr);

                       

              

Of course, this is a bug. Maple simply can't handle this differential equation and produces an incorrect result.
We can first find the general solution without using the initial condition, and then adjust the constants _C1  and  _C2   so that the desired initial condition is satisfied:

ode:=diff(y(x),x$2)-2*diff(y(x),x)+y(x)=4*exp(-x);
IC:=y(infinity)=0;
sol:=dsolve(ode); # The general solution

                  

limit(eval(y(x),sol),x=infinity) assuming _C1<>0;
limit(eval(y(x),sol),x=infinity) assuming _C1=0;

# Check
limit(eval(y(x),sol),x=infinity) assuming _C1=0,_C2=0;
eval(ode,[sol,_C1=0,_C2=0]);

                                      

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