nm

11353 Reputation

20 Badges

13 years, 8 days

MaplePrimes Activity


These are answers submitted by nm

Use StringTools and make sure y is "y"

fx:=3*x^2-9*y;
str:=String(fx);
hasy:=StringTools:-Has(str,"y")

   true

The `->` confuses the translator. It is a `Rule` in Mathematica.  For correct translation use what Mathematica uses in its internal FullForm of the expression instead of the displayed Form. i.e replace `->` by `Rule` which is what it is.

So your code now works and becomes

restart

MmaTranslator:-FromMma("Subscript[x, 0] -> 2 (y - z)^2"); # should return: x[0] = 2*(y - z)^2

x[0] = (2*y-2*z)^2

MmaTranslator:-FromMma("Rule[ Subscript[x, 0],2 (y - z)^2]"); # should return: x[0] = 2*(y - z)^2

x[0] = 2*(y-z)^2

MmaTranslator:-FromMma("a -> 2*(y - z)^2");

a = (2*y-2*z)^2

MmaTranslator:-FromMma("Rule[a,2*(y - z)^2]");

a = 2*(y-z)^2

 


 

Download use_rule.mw

On a side note, I would avoid translating code with Subscript to Maple. Maple translates Subscript[x, 0] to indexed variable. Which on the screen looks like x__0 in Maple. But it is not the same. This can cause errors in your translated code if you mix it with your own Maple code which uses x__0 and not x[0].

i.e. Subscript[x, 0]  is translated to x[0] in Maple and not to x__0, and these are different types in Maple.

Here is example

restart;

e:=MmaTranslator:-FromMma(`Subscript[x, 0]`);

x[0]

whattype(e);

indexed

lprint(e);

x[0]

e:=x__0;

x__0

whattype(e);

symbol

lprint(e);

x__0


btw, I never ever use Subscripted variables in Mathematica. This has nothing to do with translation to Maple, but these cause their own share of problems in Mathematica itself. stackexchange Mathematica forum has dozens of questions related to using Subscripted variables in Mathematica and almost eveyone says to avoid them in Mathematica.

 

Download use_rule_V2.mw

 

plots:-polarplot(4, coordinateview = [0 .. 6,0 .. 2*Pi], thickness = 3,tickmarks=[default, 2*Pi/(Pi/12)]);

 

 

pde:=diff(u(x,t),x$2)-(v-2)*u(x,t)-(v-v1/mu)*(-u(x,t)^3+u(x,t)^5)=0

diff(diff(u(x, t), x), x)-(v-2)*u(x, t)-(v-v1/mu)*(-u(x, t)^3+u(x, t)^5) = 0

xx:=solve(zeta=sqrt(k)*(x-c*t),x);

(k^(1/2)*c*t+zeta)/k^(1/2)

tr:={x=xx,u(x,t)=U(zeta)};

 

{x = (k^(1/2)*c*t+zeta)/k^(1/2), u(x, t) = U(zeta)}

pde2:=PDEtools:-dchange(tr,pde,{U,zeta},'known'={u(x,t)},'unknown'={U(zeta)})

(diff(diff(U(zeta), zeta), zeta))*k-(v-2)*U(zeta)-(v-v1/mu)*(-U(zeta)^3+U(zeta)^5) = 0

pde3:=PDEtools:-dchange({U(zeta)=sqrt(W(zeta))},pde2,{W},'known'={U(zeta)},'unknown'={W(zeta)})

(-(1/4)*(diff(W(zeta), zeta))^2/W(zeta)^(3/2)+(1/2)*(diff(diff(W(zeta), zeta), zeta))/W(zeta)^(1/2))*k-(v-2)*W(zeta)^(1/2)-(v-v1/mu)*(-W(zeta)^(3/2)+W(zeta)^(5/2)) = 0

expand(pde3*sqrt(W(zeta)))

-(1/4)*k*(diff(W(zeta), zeta))^2/W(zeta)+(1/2)*(diff(diff(W(zeta), zeta), zeta))*k-W(zeta)*v+2*W(zeta)+W(zeta)^2*v-W(zeta)^3*v-W(zeta)^2*v1/mu+W(zeta)^3*v1/mu = 0

collect(%,W(zeta));

(-v+v1/mu)*W(zeta)^3+(v-v1/mu)*W(zeta)^2+(-v+2)*W(zeta)+(1/2)*(diff(diff(W(zeta), zeta), zeta))*k-(1/4)*k*(diff(W(zeta), zeta))^2/W(zeta) = 0

 


 

Download transformation.mw

convert the result to set, this will automatically remove duplicates.


 

restart;

interface(rtablesize=70);


result:=Array(1..0):
phi := (p__1, p__2, p__3, p__4, q__1, q__2, q__3, q__4, xi) -> (p__1*cosh(xi) - p__2*sinh(xi))/(p__3*cosh(xi) + p__4*sinh(xi));
xi := x:
for p__1 in [1, -1, I, -I] do
    for p__2 in [1, -1, I, -I] do
        for p__3 in [1, -1, -I, I] do
            for p__4 in [0] do
                for q__1 in [1, -1, I, -I] do
                    for q__2 in [1, -1, I, -I] do
                        for q__3 in [1, -1, I, -I] do
                            for q__4 in [1, -1, I, -I] do
                                result ,=evalf(phi(p__1, p__2, p__3, p__4, q__1, q__2, q__3, q__4, xi)):
                                #print('phi'(p__1, p__2, p__3, p__4, q__1, q__2, q__3, q__4, xi) = result1);
                            od:
                       od:
                    od:
                od:
            od:
         od:
     od:
od:

[10, 10]

proc (p__1, p__2, p__3, p__4, q__1, q__2, q__3, q__4, xi) options operator, arrow; (p__1*cosh(xi)-p__2*sinh(xi))/(p__3*cosh(xi)+p__4*sinh(xi)) end proc

print("Before, the size was ",numelems(result));
result_no_duplidates:=convert(convert(result,set),list):
print("After remvoing duplicates, the size is ",nops(result_no_duplidates));
map(X->[''phi(p__1, p__2, p__3, p__4, q__1, q__2, q__3, q__4, xi)'' = X],result_no_duplidates):
Matrix(%);

"Before, the size was ", 16384

"After remvoing duplicates, the size is ", 64

Matrix(%id = 36893489808398873292)

 


 

Download A.mw

I do not think there is conversion builtin in Maple for this, at least I could not find one.  But see if this does what you want for now. I only tested it on your input !

e0:=int(x^(1/2),x);
evalindets(e0,sqrt,F->sqrt(op(1,F)^numer(op(2,F))))

Update

For more general cases, (for your other comment below also) you can try this function called mySimplify


 

restart;

mySimplify :=e->evalindets(e,`^`,F->`if`( op(2,F)::fraction, surd( op(1,F)^numer(op(2,F)), denom(op(2,F))),F)):
test_cases:=[  int( (x^2)^(1/3),x), int(x^(1/2),x), x^(2/3) ]:
Matrix(map(X->[X,mySimplify(X)], test_cases))

Matrix(3, 2, {(1, 1) = (3/5)*x*(x^2)^(1/3), (1, 2) = (3/5)*x*(x^2)^(1/3), (2, 1) = (2/3)*x^(3/2), (2, 2) = (2/3)*sqrt(x^3), (3, 1) = x^(2/3), (3, 2) = (x^2)^(1/3)})

 


 

Download mysimplify.mw

while running my code i am not able to edit it

If you mean you are running something in the worksheet, and while it is sitll running you can't edit or do anything? If so, then this is by design. Maple interface can't handle making any changes to worksheet while it is running something. You have to wait until computation is done.

Make sure you set each worksheet to separate engine. This is a nice feature in Maple.

This way while one sheet is busy, you can always open new worksheet and use that because each will be using new engine. See options on how to change this setting.

 

although my code is working for one pde but while changing pde it is giving me error why?

Good chance you have made some error typing the new pde or the new command. The error message you get should make it clear why.

 some times it takes alot of time to evaluate is there any error in the code or should i change my laptop?

You should use the command timelimit look it up in help. You set a timeout how long some computation should take. The general format for doing this can be something like

try
   result := timelimit(30, some_maple_command); #30 seconds timeout
catch:
  print("Warning, The command has timed out");
  result:= FAIL;
end try;

You do not need to get new laptop. Many CAS computations take long time or hang. So you should always use timelimit to guard against this. Ofcourse having faster PC with more memory is not going to hurt if you can afford it. 

 

PDEtools:-Infinitesimals

compute the infinitesimals of symmetry groups admitted by a given PDE system

25944

pde:= diff(u(t,x,y),t$2)+2*a(t)*diff(u(t,x,y),x)^2+2*b(t)*u(t,x,y)*diff(u(t,x,y),x$2)+diff(u(t,x,y),y$2)=0;
PDEtools:-Infinitesimals(pde,u(t,x,y))

diff(diff(u(t, x, y), t), t)+2*a(t)*(diff(u(t, x, y), x))^2+2*b(t)*u(t, x, y)*(diff(diff(u(t, x, y), x), x))+diff(diff(u(t, x, y), y), y) = 0

[_xi[t](t, x, y, u) = 0, _xi[x](t, x, y, u) = 1, _xi[y](t, x, y, u) = 0, _eta[u](t, x, y, u) = 0], [_xi[t](t, x, y, u) = 0, _xi[x](t, x, y, u) = 0, _xi[y](t, x, y, u) = 1, _eta[u](t, x, y, u) = 0], [_xi[t](t, x, y, u) = 0, _xi[x](t, x, y, u) = x, _xi[y](t, x, y, u) = 0, _eta[u](t, x, y, u) = 2*u]

 

 

Download lie_pde.mw

Do not know if this will work for what you are doing or not.
 

26000

restart;

26000

interface(typesetting=extended);

extended

make_nice:=proc(k::anything)
     evalindets(k,`&*`(anything,'specfunc(ln)'),F->InertForm:-MakeInert(F));
end proc;

proc (k::anything) evalindets(k, `&*`(anything, 'specfunc(ln)'), proc (F) options operator, arrow; InertForm:-MakeInert(F) end proc) end proc

k:=3/8*ln(55/52);

(3/8)*ln(55/52)

make_nice(k)

`%*`(`%/`(3, 8), %ln(`%/`(55, 52)))

k:=3/8*ln(55/52)+sin(x)+3/4*exp(x);

(3/8)*ln(55/52)+sin(x)+(3/4)*exp(x)

make_nice(k)

`%*`(`%/`(3, 8), %ln(`%/`(55, 52)))+sin(x)+(3/4)*exp(x)

 


 

Download make_nice.mw

From help it says subs does not work on contravariant indecies. Only on covariant. So need to use SubstituteTensorIndices from Physics package, See help page on SubstituteTensorIndices for more info.  It says to use subs on contra need to use ~=~ format then it should work.

I am using V 2024. If this does not work for you, may be it is version issue then,

20936

restart;

20936

with(Physics):
Setup(mathematicalnotation = true);
Define(A, B):
e:=g_[alpha, mu] * A[~mu] * g_[~alpha, ~nu] * B[nu, sigma, ~rho];

[mathematicalnotation = true]

`Defined objects with tensor properties`

Physics:-g_[alpha, mu]*A[`~mu`]*Physics:-g_[`~alpha`, `~nu`]*B[nu, sigma, `~rho`]

subs(alpha = beta,e); #does not change contra

Physics:-g_[beta, mu]*A[`~mu`]*Physics:-g_[`~alpha`, `~nu`]*B[nu, sigma, `~rho`]

SubstituteTensorIndices(alpha = beta,e); #changes contra and covariant

Physics:-g_[beta, mu]*A[`~mu`]*Physics:-g_[`~beta`, `~nu`]*B[nu, sigma, `~rho`]

#help says this should work.
subs(~alpha = ~beta,e); #changes contra only OK

Physics:-g_[alpha, mu]*A[`~mu`]*Physics:-g_[`~beta`, `~nu`]*B[nu, sigma, `~rho`]

 

 

Download tensor_june_14_2024.mw

I never heard of the method of isodine. May be you meant isoclines  ?

To make slope plot do

ode:= x+y(x)*diff(y(x),x)=0;
DEtools:-DEplot(ode,y(x),x=-2..2,y=-3..3)

To get the solution, the command is 

dsolve(ode)

To get step by step solution the command is

Student:-ODEs:-ODESteps(ode);

evalb(expand(sin(x + y))= sin(x)*cos(y) + cos(x)*sin(y)); 

    true

Maple does not expand by default. (which is a good thing)

Can you recommend a good way to find out if two terms are equivalent?

There are few ways. One easy way is to do simplify(A-B) and see if you get zero

simplify(sin(x + y) - (sin(x)*cos(y) + cos(x)*sin(y)))
 
      0

But ofcourse this depends how good the simplify command is. Also you can help the simplify with assumptions if needed.

There is also the command is and coulditbe to try

is(sin(x + y) = sin(x)*cos(y) + cos(x)*sin(y))

              true

There might be other ways.  I had few false positives from coulditbe so be careful with it.

worksheet below generates this pdf

THis is latex generated

\documentclass[12pt,a4paper]{article}
\usepackage[letterpaper,margin=1.2in]{geometry}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[label=\arabic*)]
\item $A(-12; 2; -1)$,\quad $B(-11; 1; -5)$ \quad $C(-10; -2; 3)$, \quad $(P) :10 x +6 y +z +109 = 0$
\item $A(-12; 2; -1)$,\quad $B(-11; 1; -5)$ \quad $C(-10; 6; 3)$, \quad $(P) :2 x -2 y +z +29 = 0$
\item $A(-12; 2; -1)$,\quad $B(-11; 1; -5)$ \quad $C(-9; 5; -7)$, \quad $(P) :3 x -y +z +39 = 0$
\end{enumerate}
\end{document}


 

restart;

20724

mylist := [[[-12, 2, -1], [-11, 1, -5], [-10, -2, 3], 10*x + 6*y + z + 109 = 0], [[-12, 2, -1], [-11, 1, -5], [-10, 6, 3], 2*x - 2*y + z + 29 = 0], [[-12, 2, -1], [-11, 1, -5], [-9, 5, -7], 3*x - y + z + 39 = 0]]

[[[-12, 2, -1], [-11, 1, -5], [-10, -2, 3], 10*x+6*y+z+109 = 0], [[-12, 2, -1], [-11, 1, -5], [-10, 6, 3], 2*x-2*y+z+29 = 0], [[-12, 2, -1], [-11, 1, -5], [-9, 5, -7], 3*x-y+z+39 = 0]]

currentdir("C:/tmp"); #CHANGE TO WHERE YOU WANT TO SAVE LATEX FILE

"C:\Program Files\Maple 2024"

latex:-Settings(useimaginaryunit=i,
          usecolor = false,
          powersoftrigonometricfunctions= mixed, ## computernotation,
          leavespaceafterfunctionname = true,
          cacheresults = false,
          spaceaftersqrt = true,
          usetypesettingcurrentsettings=true,
          linelength=1000000  
    );

[useimaginaryunit = i, usecolor = false, powersoftrigonometricfunctions = mixed, leavespaceafterfunctionname = true, cacheresults = false, spaceaftersqrt = true, usetypesettingcurrentsettings = true, linelength = 1000000]

do_my_list:=proc(L::list,file_name::string)
   local file_id;
   local s::string,item;

   local toX:= e->latex(e,'output'='string'):

   local my_format:=proc(e)::string;
      local s::string;
      s:=toX(e);
      s:=StringTools:-Substitute(s,"[","(");
      s:=StringTools:-Substitute(s,"]",")");
      s:=StringTools:-SubstituteAll(s,",",";");
   end proc:

   try
       file_id := fopen(file_name,WRITE);
   catch:
       error StringTools:-FormatMessage(lastexception[2..-1]);
   end try;  

   s:=cat("\\documentclass[12pt,a4paper]{article}\n",
   "\\usepackage[letterpaper,margin=1.2in]{geometry}\n",
   "\\usepackage{enumitem}\n",
   "\\begin{document}\n",
   "\\begin{enumerate}[label=\\arabic*)]\n"):
   fprintf(file_id,"%s",s);
   for item in L do

      s:=cat("\\item $A",my_format(item[1]),"$,\\quad $B",
         my_format(item[2]),"$ \\quad $C",my_format(item[3]),
         "$, \\quad $(P) :",toX(item[4]),"$\n");

      fprintf(file_id,"%s",s);
   od;
   s:="\\end{enumerate}\n\\end{document}\n";
   fprintf(file_id,"%s",s);
   fclose(file_id);    
end proc:

file_name:=cat(currentdir(),"/HW.tex");
do_my_list(mylist,file_name);

 


 

Download convert_list_to_latex_may_24_2024.mw

I am no expert on this. I find that using pattern matching in CAS to be more natural than using structured types to do this sort of thing. It also does not help that Maple documentation of its most important thing, which is structured typing, has so few examples to learn from. May be if Maple help had extensive examples, doing this sort of thing will not be like black magic any more to new users.

But here is an attempt. I am sure there is better way to do this in Maple.

772

f := -4*sin(x) + 2*exp(y^2) + 5 - 5*cos(x^3)*sin(y^2) + 5*sinh(x^2);
# I want to extract terms with sin, sinh, and exp in this expression
type_1:=''`*`'({anything,Or('specfunc(sin)','specfunc(sinh)','specfunc(exp)')})':
indets(f,type_1)
 

-4*sin(x)+2*exp(y^2)+5-5*cos(x^3)*sin(y^2)+5*sinh(x^2)

{-5*cos(x^3)*sin(y^2), 2*exp(y^2), -4*sin(x), 5*sinh(x^2)}

#I want to get terms having sin(x) and sin(y^2),
type_2:=`*`(And(anything,Or('specfunc(identical(y^2),sin)','specfunc(identical(x),sin)')));
select(hastype,f,type_2);

And(anything, Or(specfunc(identical(y^2), sin), specfunc(identical(x), sin)))

-4*sin(x)-5*cos(x^3)*sin(y^2)

# for terms including sinh(x^3), I want to get Void output.
type_3:='specfunc(identical(x^3),sinh)';
indets(f,type_3);

specfunc(identical(x^3), sinh)

{}

 

 

Download parsing.mw

look at evalc

expr:= exp(alpha[i]*I*t);
evalc(expr)

 

3 4 5 6 7 8 9 Last Page 5 of 20