nm

11538 Reputation

20 Badges

13 years, 115 days

MaplePrimes Activity


These are answers submitted by nm

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)

 

one way

sol := (-v + sqrt(-4*a^2*R^2 + v^2))/(2*a*omega*L);
expand(sol);
map(X->`if`( hastype(X,'anything'^(1/2)),sqrt(X^2),X),%)

Another using pattern matching

sol := (-v + sqrt(-4*a^2*R^2 + v^2))/(2*a*omega*L);
f:=proc(x)
local a,b,c,la;
if patmatch(x,b::nonunit(anything)*sqrt(a::nonunit(anything)),'la') then
   assign(la);
   RETURN(sqrt(a*b^2));
else
   RETURN(x);
fi;
end proc;
map(X->f(X),expand(sol));

note that in all the above,  sqrt(a)/b is same as sqrt(a/b^2) assuming b>0

Yes, this happens, but the important thing is that the corresponding order with the correct eigenvalue do not change.

i.e the way to read the outout is that the first eigenvalue goes with the first column, the second eigenvalue goes with the second column and so on.

So it does not matter if the eigenvector columns change positions, as long the the corresponding eigenvalues change in same way

 

btw, if you for some reason need to have same order of eigenvectors each time, you could always sort the eigenvector matrix columns using the numerical values of the corresponding eigenvalues as key for sorting. Something like

23920

LI:=LinearAlgebra;
M:=Matrix([[0,1],[1,0]]);

LI := LinearAlgebra

Matrix(%id = 36893490698467268956)

a,b:=LI:-Eigenvectors(M):
b[.., sort(a,output=permutation)]

Matrix(2, 2, {(1, 1) = -1, (1, 2) = 1, (2, 1) = 1, (2, 2) = 1})

a,b:=LI:-Eigenvectors(M):
b[.., sort(a,output=permutation)]

Matrix(2, 2, {(1, 1) = -1, (1, 2) = 1, (2, 1) = 1, (2, 2) = 1})

a,b:=LI:-Eigenvectors(M):
b[.., sort(a,output=permutation)]

Matrix(2, 2, {(1, 1) = -1, (1, 2) = 1, (2, 1) = 1, (2, 2) = 1})

a,b:=LI:-Eigenvectors(M):
b[.., sort(a,output=permutation)]

Matrix(2, 2, {(1, 1) = -1, (1, 2) = 1, (2, 1) = 1, (2, 2) = 1})

a,b:=LI:-Eigenvectors(M):
b[.., sort(a,output=permutation)]

Matrix(2, 2, {(1, 1) = -1, (1, 2) = 1, (2, 1) = 1, (2, 2) = 1})

a,b:=LI:-Eigenvectors(M):
b[.., sort(a,output=permutation)]

Matrix(2, 2, {(1, 1) = -1, (1, 2) = 1, (2, 1) = 1, (2, 2) = 1})

 

 

Download sorted_V.mw

Maple 2024

I have feeling there is a better or more direct way to do this but could not find it so far. But here is an attempt

Opps. Fix to make true matrix

R:=Vector[row]([1,2,3]);
C:=Vector([d,e,f]);
convert(convert(map(X->X*C,R),listlist),Matrix);
whattype(%);
LinearAlgebra:-Dimension(%%);

 

You should really post plain text code. One can't copy code from image. But you can try

sol:=signum(-sigma+q)^2;
simplify(sol) assuming real;

You should really post plain text code next time or at least worksheet.

I tried this in Maple 2024 and Mathematica 14. Both give solution that validate.  Here is Maple's

ode1:= diff(c(T),T)=-2*c(T)*(1+beta__c*c(T)^2/p__c(T)^2);
ode2:= diff(p__c(T),T)=2*(1+beta__c*c(T)^2/p__c(T)^2)*p__c(T);
sol:=[dsolve([ode1,ode2],[c(T),p__c(T)],'explicit')]


 

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

restart;

212532

ode1:= diff(c(T),T)=-2*c(T)*(1+beta__c*c(T)^2/p__c(T)^2);
ode2:= diff(p__c(T),T)=2*(1+beta__c*c(T)^2/p__c(T)^2)*p__c(T);
sol:=[dsolve([ode1,ode2],[c(T),p__c(T)],'explicit')]

diff(c(T), T) = -2*c(T)*(1+beta__c*c(T)^2/p__c(T)^2)

diff(p__c(T), T) = 2*(1+beta__c*c(T)^2/p__c(T)^2)*p__c(T)

[{c(T) = -(1/2)*64^(1/2)*(beta__c*c__2/(8*c__1*(exp(T))^8+64*c__2)^(1/2))^(1/2)/beta__c, p__c(T) = -((1/2)*I)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)}, {c(T) = (1/2)*64^(1/2)*(beta__c*c__2/(8*c__1*(exp(T))^8+64*c__2)^(1/2))^(1/2)/beta__c, p__c(T) = -((1/2)*I)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)}, {c(T) = -(1/2)*64^(1/2)*(beta__c*c__2/(8*c__1*(exp(T))^8+64*c__2)^(1/2))^(1/2)/beta__c, p__c(T) = ((1/2)*I)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)}, {c(T) = (1/2)*64^(1/2)*(beta__c*c__2/(8*c__1*(exp(T))^8+64*c__2)^(1/2))^(1/2)/beta__c, p__c(T) = ((1/2)*I)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)}, {c(T) = -2*(-2*beta__c*c__2/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2)/beta__c, p__c(T) = -(1/2)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)}, {c(T) = (1/2)*(-64*beta__c*c__2/(8*c__1*(exp(T))^8+64*c__2)^(1/2))^(1/2)/beta__c, p__c(T) = -(1/2)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)}, {c(T) = -2*(-2*beta__c*c__2/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2)/beta__c, p__c(T) = (1/2)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)}, {c(T) = (1/2)*(-64*beta__c*c__2/(8*c__1*(exp(T))^8+64*c__2)^(1/2))^(1/2)/beta__c, p__c(T) = (1/2)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)}]

map(X->odetest(X,[ode1,ode2]),sol)

[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]

 


 

Download it_works_for_me.mw

Here is Mathematica code I tried.

ClearAll["Global`*"]
ode1 = c'[T] == -2*c[T]*(1 + \[Beta]*c[T]^2/pc[T]^2);
ode2 = pc'[T] == 2*(1 + \[Beta]*c[T]^2/pc[T]^2)*pc[T];
sol = DSolve[{ode1, ode2}, {c, pc}, T]

Solution also verifies OK

Since both solutions from Maple and Mathematica verfiy OK, then both are correct even though they look different. 

set has no implied ordering. So need to use list.  Here is one way out of many

X:=[x12, x1, x3, x15, x2, x9];

f:=proc(a,b)::truefalse;
     :-parse(String(a)[2..]) < :-parse(String(b)[2..]) ;
end proc:

sort(X,f);

may be

n:=294912:
d:=8:
eq:=d^m=n/2:
floor(solve(eq,m)):
n/(d^%);

        9

This assume n is even 

You can easily modify it for odd

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