nm

11353 Reputation

20 Badges

13 years, 8 days

MaplePrimes Activity


These are answers submitted by nm

Verification:

ode:=diff(y(x),x)=(x+y(x))/(y(x)-3);
mysol:=1/2*ln( ((y(x)-3)/(x+3))^2- (y(x)-3)/(x+3)-1)-sqrt(5)/5*arctanh( sqrt(5)/5*(2*(y(x)-3)/(x+3)-1))=ln(1/(x+3))+_C1;
odetest(mysol,ode)

           0

 

You can't collect on product of terms. 

One possible way could be to use algsubs to replace sin(W)*cos(W) by new unused symbol, then do the collect, then replace the symbol back with sin(W)*cos(W)

interface(version);

`Standard Worksheet Interface, Maple 2024.2, Windows 10, October 29 2024 Build ID 1872373`

restart;

expr:=p*B[1]*sin(W) + p*A[1]*cos(W) + p*A[0] - s*B[1]*sin(W) - s*A[1]*cos(W) - s*A[0] + q*B[1]^3*sin(W)^3 + 3*q*B[1]^2*sin(W)^2*A[1]*cos(W) + 3*q*B[1]^2*sin(W)^2*A[0] + 3*q*B[1]*sin(W)*A[1]^2*cos(W)^2 + 6*q*B[1]*sin(W)*A[1]*cos(W)*A[0] + 3*q*B[1]*sin(W)*A[0]^2 + q*A[1]^3*cos(W)^3 + 3*q*A[1]^2*cos(W)^2*A[0] + 3*q*A[1]*cos(W)*A[0]^2 + q*A[0]^3 = 0

p*B[1]*sin(W)+p*A[1]*cos(W)+p*A[0]-s*B[1]*sin(W)-s*A[1]*cos(W)-s*A[0]+q*B[1]^3*sin(W)^3+3*q*B[1]^2*sin(W)^2*A[1]*cos(W)+3*q*B[1]^2*sin(W)^2*A[0]+3*q*B[1]*sin(W)*A[1]^2*cos(W)^2+6*q*B[1]*sin(W)*A[1]*cos(W)*A[0]+3*q*B[1]*sin(W)*A[0]^2+q*A[1]^3*cos(W)^3+3*q*A[1]^2*cos(W)^2*A[0]+3*q*A[1]*cos(W)*A[0]^2+q*A[0]^3 = 0

Z:='Z':
algsubs(sin(W)*cos(W)=Z,expr):
collect(%, { cos(W), sin(W), Z}):
eval(%,Z=sin(W)*cos(W))

(3*q*B[1]^2*A[1]*sin(W)+3*q*B[1]*A[1]^2*cos(W)+6*q*B[1]*A[1]*A[0])*sin(W)*cos(W)+q*A[1]^3*cos(W)^3+3*q*A[1]^2*cos(W)^2*A[0]+(3*q*A[0]^2*A[1]+p*A[1]-s*A[1])*cos(W)+q*B[1]^3*sin(W)^3+3*q*B[1]^2*sin(W)^2*A[0]+(3*q*A[0]^2*B[1]+p*B[1]-s*B[1])*sin(W)+q*A[0]^3+p*A[0]-s*A[0] = 0

 

 

Download collect_jan_15_2025.mw

I cannot find in the manual how to return the O-term 

The order is found using order as you showed., To return the O-term for asympt, one way is  as below.

For series, may be you can just do O(x^order(s))

Examples below. You can change the order using the global variable Order also.

s:=asympt(x/(1-x-x^2),x);

-1/x+1/x^2-2/x^3+3/x^4-5/x^5+8/x^6-13/x^7+21/x^8-34/x^9+O(1/x^10)

s-convert(s,polynom)

O(1/x^10)

s:=series(sin(x),x=0)

series(x-(1/6)*x^3+(1/120)*x^5-(1/5040)*x^7+(1/362880)*x^9+O(x^11),x,11)

s:=series(sin(x),x=0);
O(x^order(s))

series(x-(1/6)*x^3+(1/120)*x^5-(1/5040)*x^7+(1/362880)*x^9+O(x^11),x,11)

O(x^11)

 

 

Download order_series.mw

Your design is not really correct. Never use global variables. The whole point of using a module, is that it can have local variables (seen only by methods inside the module) and API which users of the module call. These functions then can access the module local variables.  

This is called encapsulation in software.

But using module with option object seems here better. In the constructor of the object, you make the inverse. Then the object methods access this each time they are called. So the inverse is only calculated once, when the object is constructed.  Here is an example. 

This forum does not display matrices any more. It shows ? instead. So added screen shot also below the worksheet

restart;

module TM()
 option object;
 local Metric,invMetric;
 
 export ModuleCopy::static := proc( _self::TM, proto::TM, A::Matrix, $ )
    Metric:= A;
    invMetric:=LinearAlgebra:-MatrixInverse(rtable_eval(Metric, 'inplace'));
 end proc;

 export foo::static := proc(_self,$)
        RETURN(_self:-Metric);
 end proc;

 export bar::static := proc(_self,$)
        RETURN(_self:-invMetric);
 end proc;
end module;
 

module TM () local Metric, invMetric; option object; end module

A:=Matrix(3, shape = symmetric, [[1, 0, 0], [0, 1, 0], [0, 0, 1]]);
o:=Object(TM,A):
o:-foo();

Matrix(3, 3, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (2, 1) = 0, (2, 2) = 1, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1})

Matrix(%id = 36893490083217260044)

o:-bar();

Matrix(3, 3, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (2, 1) = 0, (2, 2) = 1, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1})

A:=Matrix(3, 3, [[1, 0, 0], [0, 1, 0], [0, 0, -2]]);
o:=Object(TM,A):
o:-foo();
o:-bar();

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

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

Matrix(%id = 36893490083217245716)

 


 

Download OO_dec_30_2024.mw

 

 

Globals are bad. Avoid them. 

 

there is no type mu. You can replace the line using this

unknowns := indets(rhs~(phis), {a[-1],a[0],a[1],'identical'(mu)});

Now it works.

From help on structured types it says:

                                   | identical(expr)  an expression identical to expr

read "~/skits/slapstick/boguscalculus.mw"   , but this does not work. Any idea why ?

On Unix/Linux ~ should expand to your home directory automatically. I do not know why Maple does not do it. I do not use Maple on Linux. You can try "$HOME/...." instead of "~/...." and see if this makes difference to Maple.

currentdir "/home/harpo/skits"
how do I read the file in a worksheet using from the  currentdir

After you set currentdir(), then you can always generate relative paths using the cat command. Like this

currentdir("/home/harpo/skits");
read cat(currentdir(),"/slapstick/boguscalculus.mw"):

Note that "/" works for folder separator on Linux and windows also since windows supports / also.

The above is how I do everything myself. In the driver script or driver worksheet, which runs project A (say), the first line sets currentdir() to where the project is. This line is hardcoded and does not change. 

Then in the code that follows, to read/write to any file within that project tree, just do the cat command as above.

THis way if you want to move your whole project tree to new location, you only need to change just one line of code, which is the currentdir(....) line in the top level worksheet for that project.

You are assuming solution to your second order nonlinear ode is unique.

This is not necessarily true. Look up theorem on existence and uniqueness of solutions to second order nonlinear ode. 

As long as solutions satisfy the ode (and any IC's) then it is valid. Here, all solutions (Maple's and Mathematica do).

Also sometimes solution can be mathematically equivalent but just written differently.

Btw, in Mathematica, you need to add IncludeSingularSolutions -> True option to DSolve to obtain the other singular solution that Maple shows.

I do not use Maple Flow. But in Maple, this worked

plots:-complexplot(exp(Pi*x*I),x=-2..2,grid=[10,10],labels=["Re(x)","Im(z)"])

You seem to have syntax error in your command, Try the above in Maple Flow and see if it works.

 how could an complex exponential function be expanded with Euler's formula

In Maple, one way is this

expr:=exp(Pi*x*I);
convert(expr,trig)

You can also do

evalc(expr);

DO not know if these will work in Maple Flow or not, I assume they will, I never used Maple Flow and know nothing about it.

which then uses the value of the variable in the saved filename

Maple automatically converts integer to string when conctentating. I found this myself by accident sometime ago.  i.e. there is no need to do special conversion of variable to string, which simplifies the code.

So all you have to do it

file_name:=cat("my_file_",0,"_",200,".txt")

Or

n:=99;
file_name:=cat("my_file_",n,"_",n+1,".txt")

or

for n from 1 to 5 do
    file_name:=cat("my_file_",n,".txt");
od;

Now you can use the file_name for creating file with that name.

but have received the root of.

You can't hope to remove RootOf of this as it stands. 

But you could evaluate the solution for specific numerical values of your parameters A,Br, beta, k, m and then solve numerically.

Something like this

lambda[0] := k/(k + 1):

P := -6*x*((x - 1)^4*(A + (-1/3 - (4*Br)/21)*m)*k^8 - 4*(((A*beta + (15*Br*m)/56)*lambda[0]^3 + (-(9*A*beta)/5 - (15*Br*m)/28)*lambda[0]^2 + (4*A*beta*lambda[0])/3 + (-(7*beta)/18 + 5)*A - 20*(Br + 7/4)*m/21)*x + (-2*A*beta - (15*Br*m)/28)*lambda[0]^3 + ((18*A*beta)/5 + (15*Br*m)/14)*lambda[0]^2 - (8*A*beta*lambda[0])/3 + (7*A*beta)/9)*(x - 1)^3*k^7/5 + (12*(x - 1)^2*(((A*beta + (15*Br*m)/56)*lambda[0]^3 + (-(9*A*beta)/5 - (5*Br*m)/7)*lambda[0]^2 + (4*A*beta*lambda[0])/3 + (-(14*beta)/27 + 5/2)*A - 10*(Br + 7/4)*m/21)*x^2 + ((-A*beta - (15*Br*m)/56)*lambda[0]^3 + ((9*A*beta)/5 + (15*Br*m)/14)*lambda[0]^2 - (4*A*beta*lambda[0])/3 + (7*A*beta)/9)*x + (-(4*A*beta)/3 - (5*Br*m)/14)*lambda[0]^3 + ((12*A*beta)/5 + (5*Br*m)/28)*lambda[0]^2 - (16*A*beta*lambda[0])/9 + (7*A*beta)/54)*k^6)/5 - 12*(((A*beta + (5*Br*m)/28)*lambda[0]^3 + (-(9*A*beta)/5 - (15*Br*m)/14)*lambda[0]^2 + (8*A*beta*lambda[0])/9 + (-(7*beta)/9 + 5/3)*A - 20*(Br + 7/4)*m/63)*x^3 + (5/14*m*Br*lambda[0]^3 + 15/14*Br*m*lambda[0]^2 + 16/9*A*beta*lambda[0] + 7/9*A*beta)*x^2 + ((-A*beta - (45*Br*m)/56)*lambda[0]^3 + ((9*A*beta)/5 + (15*Br*m)/28)*lambda[0]^2 - 4*A*beta*lambda[0] + (7*A*beta)/18)*x - 2*lambda[0]*((A*beta + (5*Br*m)/56)*lambda[0]^2 - (9*A*beta*lambda[0])/5 + (4*A*beta)/9))*(x - 1)*k^5/5 + ((((4*A*beta)/5 - (3*Br*m)/7)*lambda[0]^3 + (-(72*A*beta)/25 - (12*Br*m)/7)*lambda[0]^2 - (32*A*beta*lambda[0])/15 + (1 - (56*beta)/45)*A - 4*(Br + 7/4)*m/21)*x^4 + (((15*Br*m)/7 + (4*A*beta)/5)*lambda[0]^3 + ((6*Br*m)/7 + (144*A*beta)/25)*lambda[0]^2 + (32*A*beta*lambda[0])/3 + (28*A*beta)/45)*x^3 + ((-(15*Br*m)/14 + (4*A*beta)/5)*lambda[0]^3 + (-(396*A*beta)/25 + (9*Br*m)/7)*lambda[0]^2 - (16*A*beta*lambda[0])/3 + (14*A*beta)/15)*x^2 + 4*((-(75*Br*m)/56 + A*beta)*lambda[0]^2 + (81*A*beta*lambda[0])/5 - (20*A*beta)/3)*lambda[0]*x/5 - (32*A*lambda[0]^2*(-27/40 + lambda[0])*beta)/5)*k^4 + ((((4*A*beta)/5 + (9*Br*m)/14)*lambda[0]^3 + ((3*Br*m)/7 + (108*A*beta)/25)*lambda[0]^2 + (16*A*beta*lambda[0])/5 + (14*A*beta)/45)*x^4 + ((-4*A*beta - (9*Br*m)/14)*lambda[0]^3 + (-(324*A*beta)/25 + (3*Br*m)/7)*lambda[0]^2 - (16*A*beta*lambda[0])/5 + (14*A*beta)/45)*x^3 + 8*lambda[0]*((A*beta - (3*Br*m)/28)*lambda[0]^2 + (27*A*beta*lambda[0])/25 - (8*A*beta)/15)*x^2 - 8*A*lambda[0]^2*(lambda[0] - 27/25)*beta*x - (16*A*beta*lambda[0]^3)/5)*k^3 - (12*x*lambda[0]*(((A*beta + (5*Br*m)/56)*lambda[0]^2 + (9*A*beta*lambda[0])/5 + (4*A*beta)/9)*x^3 + ((-3*A*beta + (5*Br*m)/56)*lambda[0]^2 - (9*A*beta*lambda[0])/5 + (4*A*beta)/9)*x^2 + 2*A*lambda[0]*(lambda[0] - 6/5)*beta*x + 2*A*beta*lambda[0]^2)*k^2)/5 + (12*x^2*A*((lambda[0] + 3/5)*x^2 + (-lambda[0] + 3/5)*x - (4*lambda[0])/3)*lambda[0]^2*beta*k)/5 - (4*A*x^3*beta*lambda[0]^3*(x + 1))/5)*(x - 1)*(k - 1)/(k^4*(k + 1)*((x - 1)*k - x)^6):

Pre_prime := diff(P, x):

critical_points := solve(Pre_prime = 0, x, real):

sol:=expand(eval(Pre_prime,[A=1,Br=2, beta=3, k=4, m=5]));

-(819872388/21875)*x^2/(3*x-4)^6+(338029344/21875)*x/(3*x-4)^6+(87875118/21875)*x^5/(3*x-4)^6-(89829324/4375)*x^4/(3*x-4)^6+(885207852/21875)*x^3/(3*x-4)^6-(41842368/21875)/(3*x-4)^6+(4919234328/21875)*x^3/(3*x-4)^7-(3042264096/21875)*x^2/(3*x-4)^7-(263625354/21875)*x^6/(3*x-4)^7+(1616927832/21875)*x^5/(3*x-4)^7-(3983435334/21875)*x^4/(3*x-4)^7+(753162624/21875)*x/(3*x-4)^7

solve(sol=0,x);

RootOf(4556250*_Z^5-26043039*_Z^4+60067458*_Z^3-69517416*_Z^2+40248992*_Z-9298304, index = 1), RootOf(4556250*_Z^5-26043039*_Z^4+60067458*_Z^3-69517416*_Z^2+40248992*_Z-9298304, index = 2), RootOf(4556250*_Z^5-26043039*_Z^4+60067458*_Z^3-69517416*_Z^2+40248992*_Z-9298304, index = 3), RootOf(4556250*_Z^5-26043039*_Z^4+60067458*_Z^3-69517416*_Z^2+40248992*_Z-9298304, index = 4), RootOf(4556250*_Z^5-26043039*_Z^4+60067458*_Z^3-69517416*_Z^2+40248992*_Z-9298304, index = 5)

map(X->evalf(X),[%])

[.8354684271, 1.053165735+.2330961086*I, 1.387046718+.4189727818*I, 1.387046718-.4189727818*I, 1.053165735-.2330961086*I]

 

 

Download remove_rootof_numerically_nov_9_2024.mw

I tried converting an outupt to a string which removed all the backslashes in the file path. Maybe there is a dedicated command that I overlooked.

Here is a proc that removes the user name from libname. You can test more to see if it works for you

restart;

clean_my_libname:=proc(the_libname::list)
local item::string;
local n::integer,m::integer;
local new_libname::list:=[];

for item in the_libname do
   n:=StringTools:-Search("\\Users",item);
   m:=StringTools:-Search("\\maple\\toolbox",item);
   if n<>0 and m<>0 then
      cat(item[1..n+5],item[m..]);
      new_libname:=[ op(new_libname), %];
   else      
      new_libname:=[ op(new_libname), item];
   fi;
od;
op(new_libname);
end proc:

my_new_libname:= clean_my_libname([libname]);

"C:\Users\maple\toolbox\2024\Physics Updates\lib", "C:\Program Files\Maple 2024\lib"

libname

"C:\Users\Owner\maple\toolbox\2024\Physics Updates\lib", "C:\Program Files\Maple 2024\lib"

 


 

Download clean_libname.mw

on my PC, windows 10, Maple 2024.2 has maple.mla of size 268 MB.

You can sort its content by size of each m file inside the mla. This is result of first top 10 entries by size

The 4th column, according to help under LibraryTools:-ShowContents  is the size in bytes of the m file.

Here is worksheet which displays all entries in Maple.mla sort by size.

interface(version);

`Standard Worksheet Interface, Maple 2024.2, Windows 10, October 29 2024 Build ID 1872373`

restart;

library := FileTools:-JoinPath(["lib", "maple.mla"], base=mapledir):

the_content:=LibraryTools:-ShowContents(library):

#sort by large size to small size
the_content:=ArrayTools:-SortBy( convert(the_content,Matrix) ,'column', 4,'descending', 'inplace' ):
the_content[1..10];

Matrix(10, 4, {(1, 1) = "evalf/int/GaussLaguerreQuadratureTable.m", (1, 2) = [2024, 3, 1, 8, 35, 48], (1, 3) = 154783114, (1, 4) = 2376962, (2, 1) = "casesplit/K.m", (2, 2) = [2024, 3, 1, 8, 30, 34], (2, 3) = 57860403, (2, 4) = 159362, (3, 1) = "subtype.m", (3, 2) = [2024, 3, 1, 8, 52, 29], (3, 3) = 62029141, (3, 4) = 139356, (4, 1) = "RegularChains.m", (4, 2) = [2024, 3, 1, 8, 31, 30], (4, 3) = 173035257, (4, 4) = 100337, (5, 1) = "inttrans/mellin/bessel/table.m", (5, 2) = [2024, 3, 1, 8, 49, 53], (5, 3) = 60561441, (5, 4) = 88741, (6, 1) = "context/defaultconfig.m", (6, 2) = [2024, 3, 1, 8, 49, 23], (6, 3) = 25630911, (6, 4) = 77254, (7, 1) = "ifactor/PollardP1/tree.m", (7, 2) = [2024, 3, 1, 8, 26, 13], (7, 3) = 83287450, (7, 4) = 74717, (8, 1) = "inttrans/invmellin/bessel/table.m", (8, 2) = [2024, 3, 1, 8, 49, 47], (8, 3) = 138871406, (8, 4) = 68185, (9, 1) = "evalf/int/GaussLegendreQuadratureTable.m", (9, 2) = [2024, 3, 1, 8, 35, 48], (9, 3) = 139687979, (9, 4) = 60871, (10, 1) = "convert/Sum/from.m", (10, 2) = [2024, 3, 1, 8, 33, 51], (10, 3) = 80273108, (10, 4) = 57302})

the_table :=Array(1..0):
the_table ,= ["m file name","size in bytes (4th column)","cummulative size in bytes"]:
total_size := 0:
for N from 1 to  LinearAlgebra:-RowDimension(the_content) do    
    current_size:=the_content[N,4]:
    total_size:= total_size+current_size:
    the_table ,= [the_content[N,1],current_size,total_size]:
    if N>20 then #remove this check to see all, as table becomes too large to show
       break;
    fi;
od:
the_table:=convert(the_table,listlist):
DocumentTools:-Tabulate(the_table,width=40,weights = [2, 1, 1]);

"Tabulate1"

 


Download lib_size_nov_5_2024.mw

Updated to add 2 columns , exact and approx solutions. ps also changed x values list. Note at x=1 we have division by zero in exact solution.

restart;

exact_sol:=1/(1-x);
approx_sol:=1 + x + 37/60*x^5 + 2/3*x^4 + 1/3*x^3 + x^2 + 2351/7560*x^9 + 781/1680*x^8 + 101/210*x^7 + 53/120*x^6 + 1/7*x^10 + 1091/23100*x^11 + 11/15600*x^13 + 11/1200*x^12;

1/(1-x)

1+x+(37/60)*x^5+(2/3)*x^4+(1/3)*x^3+x^2+(2351/7560)*x^9+(781/1680)*x^8+(101/210)*x^7+(53/120)*x^6+(1/7)*x^10+(1091/23100)*x^11+(11/15600)*x^13+(11/1200)*x^12

the_table :=Array(1..0):
the_table ,= [x,"exact solution", "approximate solution","Abs Error","Relative Error"]:
data:=[seq(i,i=0..1,0.1)];
for item in data do
    current_exact_sol:=evalf(eval(exact_sol,x=item));
    current_approx_sol:=evalf(eval(approx_sol,x=item));
    current_error := abs(current_exact_sol-current_approx_sol);
    current_relative_error := current_error/current_exact_sol;
    the_table ,= [item,current_exact_sol,current_approx_sol,current_error ,current_relative_error]:
od:
the_table:=convert(the_table,listlist):
DocumentTools:-Tabulate(the_table,width=60):

[0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0]


Download error_table_nov_5_2024.mw

igcd(45,63)

     9

So it is (A)

 is there a way to generate solutions to an ODE by producing specific parameters?

May be I am not answering the correct question. Why not do something similar to you question How-I-Can-Give-Assumption-To-A-ODE-Equation  where you setup the values in list and iterate over them?

btw, I assumed m->1^{-} means limit as m->1 from left.   some of these values when substituted into the ode and m is replaced by 1, give same ode!. You can add more parameters as needed.

restart;

data:=[ [P=m^2,Q=-(1+m^2),R=1],
        [P=1,Q=-(1+m^2),R=m^2],
        [P=-m^2,Q=2*m^2-1,R=1-m^2],
        [P=1,Q=2*m^2-1,R=-m^2*(1-m^2)],
        [P=1/4,Q=(m^2-2)/2,R=m^2/4],
        [P=m^2/4,Q=(m^2-2)/2,R=m^2/4]
        ]:
the_result :=Array(1..0):
the_result ,= [P,Q,R,"current ode","solution"]:
ode:=diff(F(xi),xi)^2=P*F(xi)^4+Q*F(xi)^2+R:
for item in data do
    current_ode:=limit(eval(ode,item),m=1,'left'):
    sol:=[dsolve(current_ode)]:
    the_result ,= [rhs(item[1]),rhs(item[2]),rhs(item[3]),current_ode,sol]:        
od:
the_result:=convert(the_result,listlist):
DocumentTools:-Tabulate(the_result,weights=[10,20,20,45,45],width=60):


 

Download ode_answer_oct_26_2024.mw


 

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