Kitonum

21760 Reputation

26 Badges

17 years, 201 days

MaplePrimes Activity


These are answers submitted by Kitonum

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]);

                                      

restart;
expr:=sqrt(4 + (-2*x - 2)*y):
content(expr)*primpart(expr);



Addition. It takes some extra effort to get the perfect result. Does anyone know how to make it shorter?

restart;
expr:=sqrt(4 + (-2*x - 2)*y):
content(expr)*primpart(expr);
applyop(collect, [2,1], %, y);
subs(y=-y, applyop(`/`, [2,1,2,1], %, -1));

                 

For greater clarity and informativeness, I made significant changes to the original code:

1. When creating complex animations, it's more convenient to first record one frame as a procedure and then use that procedure in the  plots:-animate  command.
2. Since the left half of the parabola isn't used in any way, I replaced it with the desired table.
3. I reduced the number of parameters to 7  (the number n runs through the values ​​from the list  [2, 4, 8, 16, 32, 64, 128]), but each subsequent parameter  n  is equal to twice the previous one.
4. The picture for each  n  lasts 1 second, since it's allocated 10 frames.


 

NULL

Approximation d'une intégrale

NULL

NULL

NULL

 

NULL

restart

with(Student:-Calculus1)

G := plot(x^2, x = 0 .. 2, gridlines, thickness = 3, color = "Blue")

OneFrame := proc (n) local P1, P2, L1, L2, T; P1 := RiemannSum(x^2, x = 0 .. 2, method = upper, output = plot, partition = n, caption = "", boxoptions = [filled = [color = "LightBlue"]]); P2 := RiemannSum(x^2, x = 0 .. 2, method = lower, output = plot, partition = n, caption = "", boxoptions = [filled = [color = "Red"]]); L1 := seq(plottools:-line([-1.9, k], [-.3, k]), k = 2.2 .. 2.8, .3); L2 := seq(plottools:-line([k, 2.2], [k, 2.8]), k = -1.9 .. -.3, .4); T := plots:-textplot([[-1.7, 2.65, "n"], [-1.3, 2.65, "Upper  \n sum"], [-.9, 2.65, "Lower  \n sum"], [-.5, 2.65, "Integral"], [-1.7, 2.35, n, font = [times, 18], color = blue], [-1.3, 2.35, evalf[4](RiemannSum(x^2, x = 0 .. 2, method = upper, partition = n)), font = [times, 18], color = blue], [-.9, 2.35, evalf[4](RiemannSum(x^2, x = 0 .. 2, method = lower, partition = n)), font = [times, 18], color = blue], [-.5, 2.35, evalf[4](int(x^2, x = 0 .. 2)), font = [times, 18], color = blue]], font = [times, 14]); plots:-display(P1, P2, L1, L2, T) end proc; plots:-animate(OneFrame, [n], n = `~`[`$`]([2, 4, 8, 16, 32, 64, 128], 10), background = G, paraminfo = false, size = [800, 800], gridlines = false)

   

 

 
 

     

Riemann_Anim_table_new.mw

Maple 2018.2 has the exact same bug.

Workaround:

restart;
ode:=diff(y(x),x) = 3*y(x)^(1/2)*x^(1/2); 
IC:=y(0)=2;
sol:=dsolve([ode,IC]);

                           

Another short way:

x := sqrt(sqrt(12)/(9 + sqrt(108))):
evala(x);

                             

restart;	
A:=r^(2*a)+r^2*(1+a+r^(2*a)) + r + a*r;
A1:=combine~(expand(A));
collect(A1,r);

               

We see that the  simplify command, given the same options but in different versions of Maple, can return different results. If we want to get the result we need, we need to be as clear as possible about what we want to Maple. We can generalize the original example as follows: suppose an expression contains only even-power cosines  and we need to replace them with sines. This can be done unambiguously using the Pythagorean trigonometric identity in the following form  cos(x)^2 = 1 - sin(x)^2 . The  algsubs  command is well suited for this task.

restart;
A:=sqrt(1-cos(x)^2):
B:=cos(x)^4*sin(x)^2+cos(x)^6:
MySubs:=cos(x)^2=1-sin(x)^2;
algsubs(MySubs, A);
algsubs(MySubs, B);

                         

 

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