acer

32303 Reputation

29 Badges

19 years, 309 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

restart;

kernelopts(version);

`Maple 2022.1, X86 64 LINUX, May 26 2022, Build ID 1619613`

de := diff(u(x),x$2) = Heaviside(x - a)*u(x);

diff(diff(u(x), x), x) = Heaviside(x-a)*u(x)

sol := dsolve(de, u(x), parametric);

sol := u(x) = piecewise(x < a, _C1*x+_C2, a <= x, ((1/2)*(a+1)*exp(x-a)+(1/2)*(a-1)*exp(-x+a))*_C1+((1/2)*exp(x-a)+(1/2)*exp(-x+a))*_C2)

map(collect, rhs(sol), exp, simplify);

piecewise(x < a, _C1*x+_C2, a <= x, ((1/2)*(a-1)*_C1+(1/2)*_C2)*exp(-x+a)+((1/2)*(a+1)*_C1+(1/2)*_C2)*exp(x-a))

Download de_h_exp.mw

(I had similar success in old Maple 16.02.)

The names you give the axes are your own choice, as is the orientation. You can adjust them however you want.

restart;

with(Student:-Calculus1):

VolumeOfRevolution(2*x^2 + 1, x = 0 .. 1, labels = [x,"",y],
                   output = plot, axis = vertical, axis=vertical,
                   orientation=[-90,90,0],
                   view=[-1.5..1.5,default,default]);

Download vorZ_ex.mw

Try passing the option explicit to the solve command.

1) The link for the form to make a Software Change Request is here.

(That also has a link item, in the drop menu "More" on the Mapleprimes tab menu at top.)

2) In Maple you can return to text entry mode with the shortcut Ctl-t . Does that also work in Maple Flow?

Here's an example of using sort to alter the form in which the (unique representation) of the expression is stored in the engine.

If you have some more involved answer that presents further problems then you ought to provide us with it. It often saves time for responders as well as questioners if a concrete example to reproduce the issue is provided up front.

restart;

expr := exp(U(a - b)) + a - b;

exp(U(a-b))+a-b

expr;

exp(U(a-b))+a-b

sort(expr, order=plex(b,a));

-b+a+exp(U(-b+a))

expr;

-b+a+exp(U(-b+a))

sort(expr, order=plex(a,b));

a-b+exp(U(a-b))

expr;

a-b+exp(U(a-b))

Download sort_term_ordering.mw

Here's a goal that someone might have:

   Take your Maple code snippet and programmatically translate it
   into another language such that the computations could be
   executed while relying only the stock runtime for that language
   (libc.so and libm.so or Windows equivalents, or a Python
   interpreter, etc), and without needing Maple in any runtime
   capability (including shared object library support, or its Library
   of interpretable commands, etc).

That's an interesting goal. A key aspect is the absence of any need for Maple proper, when running the translated code.

Note that your original Question doesn't make it clear whether you have these goals and restrictions.

There is currently no simple set of stock commands which can directly or easily accomplish the above stated goal (in italics above) for blocks of Maple code that generate its Graph structures, return its Matrix structures, or call almost all of the user-level commands of its GraphTheory or LinearAlgebra packages.

I'm guessing that by \cos^{i+2}(\theta) you intend cos(theta)^(i+2) in Maple syntax.

restart;

kernelopts(version);

`Maple 18.02, X86 64 LINUX, Oct 20 2014, Build ID 991181`

ee := cos(theta)^i-cos(theta)^(i+2);

cos(theta)^i-cos(theta)^(i+2)

R := 2*value(IntegrationTools:-Change(Int(ee,theta=0..Pi),cos(theta)=s,s));

(1/2)*Pi^(1/2)*((-1)^i+1)*GAMMA(1/2+(1/2)*i)/GAMMA(2+(1/2)*i)

seq(R, i=0..20);

Pi, 0, (1/4)*Pi, 0, (1/8)*Pi, 0, (5/64)*Pi, 0, (7/128)*Pi, 0, (21/512)*Pi, 0, (33/1024)*Pi, 0, (429/16384)*Pi, 0, (715/32768)*Pi, 0, (2431/131072)*Pi, 0, (4199/262144)*Pi

seq(int(ee,theta=0..2*Pi), i=0..20);

Pi, 0, (1/4)*Pi, 0, (1/8)*Pi, 0, (5/64)*Pi, 0, (7/128)*Pi, 0, (21/512)*Pi, 0, (33/1024)*Pi, 0, (429/16384)*Pi, 0, (715/32768)*Pi, 0, (2431/131072)*Pi, 0, (4199/262144)*Pi

Download int_cos_i.mw

Are you supposing that i is an integer?  A nonnegative integer, perhaps?

There are several ways to get such a result.

R := e -> coeff~(e,[indets(e,specfunc(T))[]]):

R( numapprox:-chebyshev(exp(x),x) );

[HFloat(1.2660658777520082), HFloat(1.1303182079849698), HFloat(0.2714953395340765), HFloat(0.044336849848663804), HFloat(0.005474240442093705), HFloat(5.429263119139931e-4), HFloat(4.497732295427603e-5), HFloat(3.1984364624457973e-6), HFloat(1.992124806415823e-7), HFloat(1.103677170949997e-8), HFloat(5.505896979790788e-10)]

R( numapprox:-chebyshev(exp(x),x,1e-4) );

[HFloat(1.2660658777520082), HFloat(1.1303182079849698), HFloat(0.2714953395340765), HFloat(0.044336849848663804), HFloat(0.005474240442093705), HFloat(5.429263119139931e-4)]

Download coeff_T.mw

Here's one way (which works whether your lprime is itself even, or odd).

restart;

lp:=5;

5

add(f(2*N), N=-floor(lp/2)..floor(lp/2));

f(-4)+f(-2)+f(0)+f(2)+f(4)

add(g(2*N), N=1..floor(lp/2));

g(2)+g(4)

restart;

lp:=6;

6

add(f(2*N), N=-floor(lp/2)..floor(lp/2));

f(-6)+f(-4)+f(-2)+f(0)+f(2)+f(4)+f(6)

add(g(2*N), N=1..floor(lp/2));

g(2)+g(4)+g(6)

 

Download sum_even_terms.mw

Here's another way, using inert multiplication.

The marked-up display of the result is done differently than working with the value of the result.

(In the actual Maple GUI the space between LongExpression and the x-dot is more apparent. You could also throw another %* in there too.)

restart;

interface(typesetting=extended):
with(Typesetting):
Settings(typesetdot=true):
Suppress(x(t)):

res := diff((1/2) %* LongExpression*x(t),t):

InertForm:-Display(res, inert=false);

`%*`(1/2, LongExpression)*(diff(x(t), t))

value(res);

(1/2)*LongExpression*(diff(x(t), t))

 

Download inert_mult_examp.mw

It appears as if your goal might be simply to keep the coefficients of the Vectors from being distributed throughout their respective elements.

In that case you'd be ok with active operations within the Vector elements, in addition to active Vector calls.

restart;

Str :=  "1/3*Vector([3^(1/2), -3^(1/2), 3^(1/2), 0]) -1/3*Vector([3^(1/2), 3^(1/2), 3^(1/2), 0])+ Vector([2,1,1,0])":

Set := {op(InertForm:-Parse( Str ))}:

subsindets(Set,specfunc(%Vector),value);

{-`%*`(`%/`(1, 3), Vector(4, {(1) = sqrt(3), (2) = sqrt(3), (3) = sqrt(3), (4) = 0})), `%*`(`%/`(1, 3), Vector(4, {(1) = sqrt(3), (2) = -sqrt(3), (3) = sqrt(3), (4) = 0})), Vector(4, {(1) = 2, (2) = 1, (3) = 1, (4) = 0})}

 

Download inert_Vector.mw

I'm not sure why some parts of the following attached worksheet appear like blocked yellow when rendered on this site. In the actual Maple GUI they are highlighted, but their foreground math is visible. (This site uses an old MapleNet...)

restart

with(Student:-Calculus1)

 

ShowSolution(Diff(x^5, x))

"[[,,"Differentiation Steps"],[,,(&DifferentialD;)/(&DifferentialD;x) (x^5)],["&EmptyVerySmallSquare;",,"1. Apply the" "power" "rule to the term" (&DifferentialD;)/(&DifferentialD;x) (x^5)],[,"?","Recall the definition of the" "power" "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) (x^[])=[] x^([]-1)],[,"?","This means:"],[,,(&DifferentialD;)/(&DifferentialD;x) (x^5)=[]],[,,"We can rewrite the derivative as:"],[,,5 x^4]]6""

ShowSolution(Diff(x^2*exp(x), x))

"[[,,"Differentiation Steps"],[,,(&DifferentialD;)/(&DifferentialD;x) (x^2 (e)^x)],["&EmptyVerySmallSquare;",,"1. Apply the" "product" "rule"],[,"?","Recall the definition of the" "product" "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) (f(x) g(x))=((&DifferentialD;)/(&DifferentialD;x) f(x)) g(x)+f(x) ((&DifferentialD;)/(&DifferentialD;x) g(x))],[,,f(x)=x^2],[,,g(x)=(e)^x],[,,"This gives:"],[,,((&DifferentialD;)/(&DifferentialD;x) (x^2)) (e)^x+x^2 ((&DifferentialD;)/(&DifferentialD;x) (e)^x)],["&EmptyVerySmallSquare;",,"2. Apply the" "power" "rule to the term" (&DifferentialD;)/(&DifferentialD;x) (x^2)],[,"?","Recall the definition of the" "power" "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) (x^[])=[] x^([]-1)],[,"?","This means:"],[,,(&DifferentialD;)/(&DifferentialD;x) (x^2)=[]],[,"?","So,"],[,,(&DifferentialD;)/(&DifferentialD;x) (x^2)=[]],[,,"We can rewrite the derivative as:"],[,,[]],["&EmptyVerySmallSquare;",,"3. Apply the" "exponential" "rule"],[,"?","Recall the definition of the" "exponential" "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) (e^x)=e^x],[,,"This gives:"],[,,[]]]6""

ShowSolution(Diff(x*sin(x), x))

"[[,,"Differentiation Steps"],[,,(&DifferentialD;)/(&DifferentialD;x) (x sin(x)"

ShowSolution(Diff(exp(x)*tan(x), x))

"[[,,"Differentiation Steps"],[,,(&DifferentialD;)/(&DifferentialD;x) ((e)^x tan(x))],["&EmptyVerySmallSquare;",,"1. Apply the" "product" "rule"],[,"?","Recall the definition of the" "product" "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) (f(x) g(x))=((&DifferentialD;)/(&DifferentialD;x) f(x)) g(x)+f(x) ((&DifferentialD;)/(&DifferentialD;x) g(x))],[,,f(x)=(e)^x],[,,g(x)=tan(x)],[,,"This gives:"],[,,((&DifferentialD;)/(&DifferentialD;x) (e)^x) tan(x)+(e)^x ((&DifferentialD;)/(&DifferentialD;x) tan(x))],["&EmptyVerySmallSquare;",,"2. Apply the" "exponential" "rule"],[,"?","Recall the definition of the" "exponential" "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) (e^x)=e^x],[,,"This gives:"],[,,[]],["&EmptyVerySmallSquare;",,"3. Evaluate the derivative of" tan "("x")"],[,"?","Recall the definition of the" tan "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) tan(x)=1+(tan(x))^2],[,,"This gives:"],[,,[]]]6""

ShowSolution(Diff(tan(x)*sec(x), x))

"[[,,"Differentiation Steps"],[,,(&DifferentialD;)/(&DifferentialD;x) (tan(x) sec(x))],["&EmptyVerySmallSquare;",,"1. Apply the" "product" "rule"],[,"?","Recall the definition of the" "product" "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) (f(x) g(x))=((&DifferentialD;)/(&DifferentialD;x) f(x)) g(x)+f(x) ((&DifferentialD;)/(&DifferentialD;x) g(x))],[,,f(x)=tan(x)],[,,g(x)=sec(x)],[,,"This gives:"],[,,((&DifferentialD;)/(&DifferentialD;x) tan(x)) sec(x)+tan(x) ((&DifferentialD;)/(&DifferentialD;x) sec(x))],["&EmptyVerySmallSquare;",,"2. Evaluate the derivative of" tan "("x")"],[,"?","Recall the definition of the" tan "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) tan(x)=1+(tan(x))^2],[,,"This gives:"],[,,[]],["&EmptyVerySmallSquare;",,"3. Evaluate the derivative of" sec "("x")"],[,"?","Recall the definition of the" sec "rule"],[,,(&DifferentialD;)/(&DifferentialD;x) sec(x)=tan(x) sec(x)],[,,"This gives:"],[,,[]]]6""


Integration Questions

ShowSolution(Int(5*x^4, x))

"[[,,"Integration Steps"],[,,&int;5 x^4 &DifferentialD;x],["&EmptyVerySmallSquare;",,"1. Apply the" "constant multiple" "rule to the term" &int;5 x^4 &DifferentialD;x],[,"?","Recall the definition of the" "constant multiple" "rule"],[,,&int;[] f(x) &DifferentialD;x=[] (&int;f(x) &DifferentialD;x)],[,"?","This means:"],[,,&int;5 x^4 &DifferentialD;x=5 (&int;x^4 &DifferentialD;x)],[,,"We can rewrite the integral as:"],[,,5 (&int;x^4 &DifferentialD;x)],["&EmptyVerySmallSquare;",,"2. Apply the" "power" "rule to the term" &int;x^4 &DifferentialD;x],[,"?","Recall the definition of the" "power" "rule, for n" "<>" "-1"],[,,&int;x^[] &DifferentialD;x=[]],[,"?","This means:"],[,,&int;x^4 &DifferentialD;x=[]],[,"?","So,"],[,,&int;x^4 &DifferentialD;x=(x^5)/5],[,,"We can rewrite the integral as:"],[,,x^5],["&bullet;",,"Add constant of integration"],[,,x^5+C]]6""

ShowSolution(Int(sin(x)+x*cos(x), x))

"[[,,"Integration Steps"],[,,&int;(sin(x)+x cos(x)) &DifferentialD;x],["&EmptyVerySmallSquare;",,"1. Apply the" "sum" "rule"],[,"?","Recall the definition of the" "sum" "rule"],[,,&int;(f(x)+g(x)) &DifferentialD;x=&int;f(x) &DifferentialD;x+&int;g(x) &DifferentialD;x],[,,f(x)=sin(x)],[,,g(x)=x cos(x)],[,,"This gives:"],[,,&int;sin(x) &DifferentialD;x+&int;x cos(x) &DifferentialD;x],["&EmptyVerySmallSquare;",,"2. Evaluate the integral of" sin"("x")"],[,"?","Recall the definition of the" sin "rule"],[,,&int;sin(x) &DifferentialD;x=-cos(x)],[,,"This gives:"],[,,[]],["&EmptyVerySmallSquare;",,"3. Apply integration by Parts"],[,"?","Recall the definition of the" "Parts" "rule"],[,,&int;u &DifferentialD;v=v u-(&int;v &DifferentialD;u)],[,"?","First part"],[,,u=x],[,"?","Second part"],[,,[]=cos(x)],[,"?","Differentiate first part"],[,,[]=(&DifferentialD;)/(&DifferentialD;x) x],[,,[]=1],[,"?","Integrate second part"],[,,v=&int;cos(x) &DifferentialD;x],[,,v=sin(x)],[,,&int;x cos(x) &DifferentialD;x=x sin(x)-(&int;sin(x) &DifferentialD;x)],[,,"This gives:"],[,,-cos(x)+x sin(x)-(&int;sin(x) &DifferentialD;x)],["&EmptyVerySmallSquare;",,"4. Evaluate the integral of" sin"("x")"],[,"?","Recall the definition of the" sin "rule"],[,,&int;sin(x) &DifferentialD;x=-cos(x)],[,,"This gives:"],[,,x sin(x)],["&bullet;",,"Add constant of integration"],[,,x sin(x)+C]]6""


Limit questions

ShowSolution(Limit(sin(x)/x, x = 0))

"[[,,"Limit Steps"],[,,(lim)(sin(x))/x],["&EmptyVerySmallSquare;",,"1. Apply" "L'Hôpital's Rule"],[,"?","Recall the definition of the" "L'Hôpital's Rule" "rule"],[,,(lim)(f(x))/(g(x))=(lim)((&DifferentialD;)/(&DifferentialD;x) f(x))/((&DifferentialD;)/(&DifferentialD;x) g(x))],[,"?","Rule applied"],[,,(lim)(sin(x))/x=(lim)cos(x)],[,,"This gives:"],[,,(lim)cos(x)],["&EmptyVerySmallSquare;",,"2. Evaluate the limit of" cos"("x")"],[,"?","Recall the definition of the" cos "rule"],[,,(lim)cos(f(x))=cos((lim)f(x))],[,,"This gives:"],[,,1]]6""

ShowSolution(Limit((x+2)/(x^2-4), x = -2))

"[[,,"Limit Steps"],[,,(lim)(x+2)/(x^2-4)],["&EmptyVerySmallSquare;",,"1. Factor"],[,"?","Factor a polynomial or rational function"],[,,(x+2)/(x^2-4)=1/(x-2)],[,,"This gives:"],[,,(lim)1/(x-2)],["&EmptyVerySmallSquare;",,"2. Apply the" "power" "rule"],[,"?","Recall the definition of the" "power" "rule"],[,,(lim)x^[]=((lim)x)^[]],[,,"This gives:"],[,,1/((lim)(x-2))],["&EmptyVerySmallSquare;",,"3. Apply the" "sum" "rule"],[,"?","Recall the definition of the" "sum" "rule"],[,,(lim)(f(x)+g(x))=((lim)f(x))+((lim)g(x))],[,,f(x)=x],[,,g(x)=-2],[,,"This gives:"],[,,1/(((lim)x)+(lim)(-2))],["&EmptyVerySmallSquare;",,"4. Apply the" "constant" "rule to the term" (lim)(-2)],[,"?","Recall the definition of the" "constant" "rule"],[,,(lim)C=C],[,"?","This means:"],[,,(lim)(-2)=-2],[,,"We can now rewrite the limit as:"],[,,1/(((lim)x)-2)],["&EmptyVerySmallSquare;",,"5. Apply the" "identity" "rule"],[,"?","Recall the definition of the" "identity" "rule"],[,,(lim)x=a],[,,"This gives:"],[,,-1/4]]6""

ShowSolution(Limit(x*sin(1/x), x = 0))

"[[,,"Limit Steps"],[,,(lim)x sin(1/x)],["&EmptyVerySmallSquare;",,"1. Apply the" "product" "rule"],[,"?","Recall the definition of the" "product" "rule"],[,,(lim)f(x) g(x)=((lim)f(x)) ((lim)g(x))],[,,f(x)=x],[,,g(x)=sin(1/x)],[,,"This gives:"],[,,((lim)x) ((lim)sin(1/x))],["&EmptyVerySmallSquare;",,"2. Apply the" "identity" "rule"],[,"?","Recall the definition of the" "identity" "rule"],[,,(lim)x=a],[,,"This gives:"],[,,0]]6""

 

Download Help_derivative_and_limit_ac.mw

1D Vectors and 2D Matrices can be converted to list and listlist, respectively, before being embedded in a command-string passed to Maple's bundled python interpreter.

And CodeGeneration:-Python might be able to convert your Maple expression into Python syntax,

For example,

expr := sin(X)+Y^2;

sin(X)+Y^2

cmdstr:=CodeGeneration:-Python(expr, ':-output'=string,
                               ':-resultname'=':-K')[5..-2];

"math.sin(X) + Y ** 2"

restart;

A1,A2 := <3,5,17>,<4,55,9>;

A1, A2 := Vector(3, {(1) = 3, (2) = 5, (3) = 17}), Vector(3, {(1) = 4, (2) = 55, (3) = 9})

A1 . A2;

440

with(Python):

ImportModule("numpy");

cmdstr := sprintf("numpy.dot(%a,%a)",
                  convert(A1,list),convert(A2,list) );

"numpy.dot([3, 5, 17],[4, 55, 9])"

EvalString(cmdstr);

440

cmdstr := sprintf("r=min(%a)", convert(A1,list));

"r=min([3, 5, 17])"

EvalString( cmdstr );

3

A,B := Matrix([[1,7],[-2,-30]]), Matrix([[11,7],[-22,-30]]); #<2,3>;

A, B := Matrix(2, 2, {(1, 1) = 1, (1, 2) = 7, (2, 1) = -2, (2, 2) = -30}), Matrix(2, 2, {(1, 1) = 11, (1, 2) = 7, (2, 1) = -22, (2, 2) = -30})

A . B;

Matrix(2, 2, {(1, 1) = -143, (1, 2) = -203, (2, 1) = 638, (2, 2) = 886})

cmdstr := sprintf("r=numpy.dot(%a,%a)",
                  convert(A,listlist),convert(B,listlist));

"r=numpy.dot([[1, 7], [-2, -30]],[[11, 7], [-22, -30]])"

raw := EvalString(cmdstr, output=maple);

"<Python object: [[-143 -203]
 [ 638  886]]>"

# This seems dodgy and fragile.

use SA=StringTools:-SubstituteAll in
  parse(SA(SA(SA(SA(convert(raw,string)[18..-3],
                    "[ ","["),"  "," ")," ",","),"\\n",""));
  Matrix(%);
end use;

[[-143, -203], [638, 886]]

Matrix(%id = 36893628087048528708)

Download python_ex.mw

I am not sure why the array result from Python is not better converted back to a Maple data structure.

What about invoking it as,

   p:-process(p, p)

and avoiding overhead of construction?

restart;

kernelopts(version);

`Maple 2022.1, X86 64 LINUX, May 26 2022, Build ID 1619613`

person:=module()
    option object;
    export name::string:="";  

     export ModuleCopy::static:= overload(
     [
         proc(_self,proto, $)option overload;
            print("Enter 2 args constructor of person");  
            #do nothing    
         end proc,

         proc(_self,proto, name::string, $) option overload;
             print("Enter 3 args constructor of person");      
             _self:-name := name;
        end proc
     ]);

    export process::static:=proc(_self, the_input::person,$)
       print("the_input:-name = ",the_input:-name);
    end proc;
    
end module:

p:=Object(person,"me"):

"Enter 3 args constructor of person"

p:-process(p, p);

"the_input:-name = ", "me"

Download obj_own.mw

It's not clear how much detail you want in the steps.

I put some settings and the source for the show procedure (used below) in the Startup Code section of the worksheet. I used Maple 2021.2.

restart;

 

f(x) = x^2;

f(x) = x^2

 

show(x^2, -1..2, partition=4, method=trapezoid );

0, "%1 is not a command in the %2 package", _Hold, Typesetting

.3750000000*`%+`(1, 2*(1/16), 2*(1/4), (2*(25/16))*`,`(4))

.3750000000*`%+`(1., 2*0.6250000000e-1, 2*.2500000000, (2*1.562500000)*`,`(4.))

3.281250000

 

show(x^2, -1..2, partition=2, method=simpson );

0, "%1 is not a command in the %2 package", _Hold, Typesetting

.2500000000*`%+`(1, 4*(1/16), 2*(1/4), (4*(25/16))*`,`(4))

.2500000000*`%+`(1., 4*0.6250000000e-1, 2*.2500000000, (4*1.562500000)*`,`(4.))

3.000000000

Download trap_simp_steps.mw

First 65 66 67 68 69 70 71 Last Page 67 of 336