nm

11538 Reputation

20 Badges

13 years, 115 days

MaplePrimes Activity


These are answers submitted by nm

export to eps then convert to pdf or png as needed.  use the noborder option for the plotsetup.

This is the pdf output

restart;
currentdir("...");
p:=plot(x^2, x = 0 .. 3, background = "Blue", axes = none);
plotsetup(default);
plotsetup(ps, plotoutput="my_image",plotoptions=`color,noborder`);
print(p);
plotsetup(default);

Humm, You can not use diff(u(x, 0), t)  as is for IC. This is same for ordinary differential equation as well as partial differential equation.

You have to use the D operator. For an ode we write  D(y)(0)=0  to give initial condition y'(0)=0. not diff(y(0),x)=0

I do not know what u__t(x, 0) is supposed to mean. Is this 2D math for document mode? I do not use 2D math for input.

I found this cheat sheet on the net so I copy it here

Just remember, if you have symbolic ic, as in   y(a)=c and if you type  D(y)(a)=c, it will fail, unless you tell Maple that the dependent variable is y(x). As in 

           dsolve([ode,D(y)(a)=b],y(x))  #must add y(x) here

If IC is numeric, as in y'(0)=b then you do not need to add y(x), so this works

           dsolve([ode,D(y)(0)=b])  #no need to add y(x) here, but it will not hurt if added

Same for pde. 

But If you really want to use diff, which I do not recommend, and better stick to D, then you can use this syntax instead. 

IC := u(x, 0) = f,  eval(diff(u(x,t),t),t=0)=g;

Student:-ODEs:-ODESteps does not support method name. If you try 

ode:=diff(y(x),x)+2*x*y(x)=x;

Student:-ODEs:-ODESteps(ode,y(x),['linear'])

#or

Student:-ODEs:-ODESteps(ode,y(x),['separable'])

You will get the same exact method used, which in this case separable.

To use different methods you need to use dsolve itself. Also DEtools:-odeadvisor(ode); is better than Student:-ODEs:-Type(ode) since it knows much more ode types. 

 

Example 1

 

ode:=diff(y(x),x)+2*x*y(x)=x;

diff(y(x), x)+2*x*y(x) = x

Student:-ODEs:-Type(ode)

{linear, separable}

dsolve(ode,['linear'])

y(x) = 1/2+exp(-x^2)*c__1

dsolve(ode,['separable'])

y(x) = -(1/2)*exp(-x^2)*c__1+1/2

 

 

 

Example 2

 

ode:=(x+y(x))*diff(y(x),x) = 1;

(x+y(x))*(diff(y(x), x)) = 1

Student:-ODEs:-Type(ode)

{}

DEtools:-odeadvisor(ode);

[[_homogeneous, `class C`], [_Abel, `2nd type`, `class C`], _dAlembert]

dsolve(ode,['dAlembert'])

y(x) = -x-1, y(x) = -x-LambertW(-c__1*exp(-x-1))-1

dsolve(ode,['Abel'])

y(x) = -x-1-LambertW(-2*c__1*exp(-1)/exp(x))

 

dsolve(ode,['homogeneous'])

y(x) = -x-LambertW(-c__1*exp(-1)/exp(x))-1

 

#to find all methods do
indices(`dsolve/methods`)

[1], [2, "linear_homogeneous other"], [high, "development"], [2, linear_homogeneous], [2, "special_functions"], [2, "hypergeometric"], [2, nonlinear], [1, high_degree], [3, linear_homogeneous], [high, linear_homogeneous], [3, linear_nonhomogeneous], [high, linear_nonhomogeneous], [2, "linear_homogeneous as given"], [1, "special"], [high, nonlinear], [1, extra], [2, linear_nonhomogeneous], [3, "development"], [1, "development"], [3, nonlinear], [2, "linear_homogeneous all methods"], [2, "linear_homogeneous in Normal Form"], [2, "development"], [1, semiclass]

`dsolve/methods`[2, "linear_homogeneous all methods"]

[quadrature, const_coeffs, Euler, linear_1, `linear/missing_y`, Kovacic, special_functions, to_const_coeffs, exact_linear, sym_1, Mathieu, MeijerG, Heun, HeunG, HeunC, HeunB, HeunD, HeunT, mu_xy, equivalent_to_Bessel, to_Riccati, Bessel, elliptic, Legendre, Whittaker, Kummer, cylindrical, hypergeometric, hypergeom1, hypergeom2, Riemann, RNF, hypergeometricsols, rationalize_lode, with_periodic_functions]

`dsolve/methods`[2, "linear_homogeneous other"]

[exact_linear, sym_1, to_const_coeffs, mu_xy, equivalent_to_Bessel, to_Riccati, with_periodic_functions]

ind:=indices(`dsolve/methods`);
for item in ind do
    cat("`dsolve/methods`",String(item));
    eval(parse(%))
od;

[1], [2, "linear_homogeneous other"], [high, "development"], [2, linear_homogeneous], [2, "special_functions"], [2, "hypergeometric"], [2, nonlinear], [1, high_degree], [3, linear_homogeneous], [high, linear_homogeneous], [3, linear_nonhomogeneous], [high, linear_nonhomogeneous], [2, "linear_homogeneous as given"], [1, "special"], [high, nonlinear], [1, extra], [2, linear_nonhomogeneous], [3, "development"], [1, "development"], [3, nonlinear], [2, "linear_homogeneous all methods"], [2, "linear_homogeneous in Normal Form"], [2, "development"], [1, semiclass]

"`dsolve/methods`[1]"

[quadrature, linear, Bernoulli, separable, inverse_linear, homogeneous, Chini, lin_sym, exact, Abel, pot_sym]

"`dsolve/methods`[2, "linear_homogeneous other"]"

[exact_linear, sym_1, to_const_coeffs, mu_xy, equivalent_to_Bessel, to_Riccati, with_periodic_functions]

"`dsolve/methods`[high, "development"]"

[k25, RNF, mu_heuristic, MeijerG, nonlinear_homogeneous, mu_poly_yn, exp_sym]

"`dsolve/methods`[2, linear_homogeneous]"

[linear_homogeneous]

"`dsolve/methods`[2, "special_functions"]"

[Bessel, elliptic, Legendre, Kummer, Whittaker, hypergeometric, Mathieu]

"`dsolve/methods`[2, "hypergeometric"]"

[hypergeom1, hyper3]

"`dsolve/methods`[2, nonlinear]"

[Liouville, WeierstrassP, JacobiSN, linearizable, linearizable_by_differentiation, mu_xy_2, missing, mu_xyp2_dynamical_symmetries_fully_reducible, mu_xyp_singularcases, sym_1, exact_nonlinear, reducible, lin_sym, `S-function`, mu_xyp_generalcase, mu_xyp2_dynamical_symmetries_not_fully_reducible]

"`dsolve/methods`[1, high_degree]"

[WeierstrassP, WeierstrassPPrime, JacobiSN, linearizable_by_differentiation, missing, dAlembert, homogeneous_B, sym_implicit]

"`dsolve/methods`[3, linear_homogeneous]"

[quadrature, const_coeffs, Euler, fully_exact_linear, to_const_coeffs, linear, exp_reduce, exact_linear, with_periodic_functions]

"`dsolve/methods`[high, linear_homogeneous]"

[quadrature, const_coeffs, Euler, fully_exact_linear, to_const_coeffs, linear, exp_reduce, exact_linear, with_periodic_functions]

"`dsolve/methods`[3, linear_nonhomogeneous]"

[quadrature, fully_exact_linear, `linear_nonhomogeneous_[0,1]`, exact_linear_nonhomogeneous, linear, exp_reduce]

"`dsolve/methods`[high, linear_nonhomogeneous]"

[quadrature, fully_exact_linear, `linear_nonhomogeneous_[0,1]`, exact_linear_nonhomogeneous, linear, exp_reduce]

"`dsolve/methods`[2, "linear_homogeneous as given"]"

[quadrature, const_coeffs, Euler, linear_1, `linear/missing_y`, Kovacic, RNF, special_functions, MeijerG, Heun, hypergeometricsols, rationalize_lode]

"`dsolve/methods`[1, "special"]"

[80, 81]

"`dsolve/methods`[high, nonlinear]"

[linearizable_by_differentiation, linearizable, reducible, exact_nonlinear, missing, mu_formal, lin_sym]

"`dsolve/methods`[1, extra]"

[inverse_Riccati, Abel_AIL, `sym_pat/[F(x)*G(y),0]`, `sym_pat/[F(x),G(x)]`, `sym_pat/[F(x),G(y)]`, `sym_pat/[F(x)+G(y),0]`, `sym_pat/[F(x),G(x)*y+H(x)]`, sym_pat, exp_sym]

"`dsolve/methods`[2, linear_nonhomogeneous]"

[quadrature, fully_exact_linear, `linear_nonhomogeneous_[0,1]`, `linear_nonhomogeneous_[0,F(x)]`, linear_nonhomogeneous]

"`dsolve/methods`[3, "development"]"

[k25, RNF, mu_heuristic, linear_patterns, MeijerG, nonlinear_homogeneous, mu_y2, mu_poly_yn, exp_sym, pFq, `3F2`, `2F2`, `1F2`, `0F2`]

"`dsolve/methods`[1, "development"]"

[linearizable_by_differentiation, linearizable, con_sym, WeierstrassP, WeierstrassPPrime, equivalent_to_Abel, Abel_AIR, special, Riccati_symmetries]

"`dsolve/methods`[3, nonlinear]"

[linearizable_by_differentiation, linearizable, missing, exact_nonlinear, reducible, mu_formal, lin_sym]

"`dsolve/methods`[2, "linear_homogeneous all methods"]"

[quadrature, const_coeffs, Euler, linear_1, `linear/missing_y`, Kovacic, special_functions, to_const_coeffs, exact_linear, sym_1, Mathieu, MeijerG, Heun, HeunG, HeunC, HeunB, HeunD, HeunT, mu_xy, equivalent_to_Bessel, to_Riccati, Bessel, elliptic, Legendre, Whittaker, Kummer, cylindrical, hypergeometric, hypergeom1, hypergeom2, Riemann, RNF, hypergeometricsols, rationalize_lode, with_periodic_functions]

"`dsolve/methods`[2, "linear_homogeneous in Normal Form"]"

[linear_1]

"`dsolve/methods`[2, "development"]"

[mu_xyp, mu_xyp2, mu_formal, mu_heuristic, exp_reduce, linear, Bessel2, Whittaker_old, nonlinear_homogeneous, exact_linear_nonhomogeneous, mu_y1, mu_x_y1, mu_y_y1, mu_poly_yn, exp_sym, sym_pat, sym_8]

"`dsolve/methods`[1, semiclass]"

[Riccati, inverse_Riccati, equivalent_to_Abel, linearizable, linearizable_by_differentiation]

 

 

Download specifiy_methods_of_dsolve.mw

you did not say which maple version you are using. but in Maple 2024 it does it just by using simplify

If this does not work in your version, try simplify(e,trig) and if this does not work, try convert(e,tanh)

one possible way is to use  TypeTools[AddType]

restart;

 

TypeTools[AddType]( my_type_A, n->evalb(n::integer and (n=10 or n=20 or n=30)) );

my_proc:=proc(a::integer, b::my_type_A)
  print(b)
end proc;

proc (a::integer, b::my_type_A) print(b) end proc

my_proc(3,10)

10

my_proc(3,7)

Error, invalid input: my_proc expects its 2nd argument, b, to be of type my_type_A, but received 7

my_proc(3,30)

30

Download my_type.mw

Another option is to use `type/....`  

I am no expert much in this area to know which method is better or more robust. 

restart

`type/my_type_A` := n->evalb(n::integer and (n=10 or n=20 or n=30))

proc (n) options operator, arrow; evalb(n::integer and (n = 10 or n = 20 or n = 30)) end proc

my_proc:=proc(a::integer, b::my_type_A)
  print(b)
end proc;

proc (a::integer, b::my_type_A) print(b) end proc

my_proc(3,10)

10

my_proc(3,7)

Error, invalid input: my_proc expects its 2nd argument, b, to be of type my_type_A, but received 7

my_proc(3,30)

30

Download my_type_2.mw

The advantage of making a name for the type, is that you can use this name in other places in your code to check if variable is of this type. Like this

restart

`type/my_type_A` := n->evalb(n::integer and (n=10 or n=20 or n=30))

proc (n) options operator, arrow; evalb(n::integer and (n = 10 or n = 20 or n = 30)) end proc

b:=30;
if b::my_type_A then
   "yes";
else
   "no";
fi;

30

"yes"

b:=31;
if b::my_type_A then
   "yes";
else
   "no";
fi;

31

"no"

Download my_type_3.mw

I've collected all Maple tech letters sometime ago from different corners of the internet.

Here is Vol 1, No 1  attached

MapleTech_volume_1_number_1_spring_1994.pdf

 

The order is important for type. Here is a much simpler example

type(1+"s",`&+`(integer,string));

    #true

Now change the order, it gives false

type(1+"s",`&+`(string,integer));

   #false

That is why your third one gave true but the first two did not, The third one had the same exact order as how Z is written.  

One would think the order of `+` operands should not matter but  it does for type.

The only way I know how to make it match all, is to use alternatives and enumerate all possible cases.  For the above example, that will be

type(1+"s", {`&+`(integer,string) 
             ,`&+`(string,integer) 
            }
    )
#true

So you'd do the same for your input. 

I do not know other ways to do it. Using `Or` does work. At least in my attempts. So I always do it this way, by listing all possible alternatives.  

Your A is equation and not polynomial. lhs(A) is a polynomial. 

So instead of 

for i from 0 to degree(A,p) do EQ[i]:=simplify(coeff(A,p,i)); end do;

Do this instead

for i from 0 to degree(lhs(A),p) do EQ[i]:=simplify(coeff(lhs(A),p,i)); end do;

And now it gives

I do not think you can do this in general because as you said, Maple will apply auto-simplification and revert the changes.

If you just want this for display purposes, this is function which you call only any expressions and it will convert the circular trig functions to use sin only. It uses InertForm:-Parse to prevent Maple from reverting it back. This handles cos.,tan,sec,cot and csc.  You can use value(%) to convert back to non inert form.

restart;

change_to_sin_only:=proc(expr)
local e,F;

  e:=evalindets(expr,specfunc(anything,cos),F->InertForm:-Parse( cat("sin(",String(op(1,F)),"+Pi/2)")));
  e:=evalindets(e,specfunc(anything,tan),F->InertForm:-Parse( cat("sin(",String(op(1,F)),")/sin(",String(op(1,F)),"+Pi/2)")));
  e:=evalindets(e,specfunc(anything,sec),F->InertForm:-Parse( cat("1/sin(",String(op(1,F)),"+Pi/2)")));
  e:=evalindets(e,specfunc(anything,cot),F->InertForm:-Parse( cat("sin(",String(op(1,F)),"+Pi/2)/sin(",String(op(1,F)),")")));
  e:=evalindets(e,specfunc(anything,csc),F->InertForm:-Parse( cat("1/sin(",String(op(1,F)),")")));
  e;
end proc:

expr:=cos(x)+sin(x)+x+tan(2*x)+sec(x)+csc(x)+cot(x)+sin(x)/cos(x)+exp(2*cos(x));

cos(x)+sin(x)+x+tan(2*x)+sec(x)+csc(x)+cot(x)+sin(x)/cos(x)+exp(2*cos(x))

change_to_sin_only(expr);

%sin(`%+`(x, `%/`(Pi, 2)))+sin(x)+x+`%/`(%sin(`%*`(2, x)), %sin(`%+`(`%*`(2, x), `%/`(Pi, 2))))+`%/`(1, %sin(`%+`(x, `%/`(Pi, 2))))+`%/`(1, %sin(x))+`%/`(%sin(`%+`(x, `%/`(Pi, 2))), %sin(x))+sin(x)/%sin(`%+`(x, `%/`(Pi, 2)))+exp(2*%sin(`%+`(x, `%/`(Pi, 2))))

simplify(value(%));

cos(x)+sin(x)+x+tan(2*x)+sec(x)+csc(x)+cot(x)+tan(x)+exp(2*cos(x))

expr:=cos(x)^3+sin(x)+1/tan(2*x);

cos(x)^3+sin(x)+1/tan(2*x)

change_to_sin_only(expr);

%sin(`%+`(x, `%/`(Pi, 2)))^3+sin(x)+1/`%/`(%sin(`%*`(2, x)), %sin(`%+`(`%*`(2, x), `%/`(Pi, 2))))

simplify(value(%));

cos(x)^3+sin(x)+cot(2*x)

 


Download convert_to_sin.mw

 

See my original post where I state it needs to be cos(x)=k*sqrt(1-sin(x)^2) 

This versions uses  this form with k +1 or -1. You can pick the one you need or feel free to modify it.

Again, this is for display only as it uses Inert form

restart;

change_to_sin_only:=proc(expr,k::integer,$)
local e,F;
  if k=-1 then
     e:=evalindets(expr,specfunc(anything,cos),F->InertForm:-Parse( cat("-1*sqrt(1-sin(",String(op(1,F)),")^2)")));
     e:=evalindets(e,specfunc(anything,cot),F->InertForm:-Parse( cat("-1*sqrt(1-sin(",String(op(1,F)),")^2)/sin(",String(op(1,F)),")")));
     e:=evalindets(e,specfunc(anything,sec),F->InertForm:-Parse( cat("1/(-1*sqrt(1-sin(",String(op(1,F)),")^2))")));
     e:=evalindets(e,specfunc(anything,csc),F->InertForm:-Parse( cat("1/sin(",String(op(1,F)),")")));
     e:=evalindets(e,specfunc(anything,tan),F->InertForm:-Parse( cat("sin(",String(op(1,F)),")/(-1*sqrt(1-sin(",String(op(1,F)),")^2))")));
  elif k=1 then
     e:=evalindets(expr,specfunc(anything,cos),F->InertForm:-Parse( cat("sqrt(1-sin(",String(op(1,F)),")^2)")));
     e:=evalindets(e,specfunc(anything,cot),F->InertForm:-Parse( cat("sqrt(1-sin(",String(op(1,F)),")^2)/sin(",String(op(1,F)),")")));
     e:=evalindets(e,specfunc(anything,sec),F->InertForm:-Parse( cat("1/(sqrt(1-sin(",String(op(1,F)),")^2))")));
     e:=evalindets(e,specfunc(anything,csc),F->InertForm:-Parse( cat("1/sin(",String(op(1,F)),")")));
     e:=evalindets(e,specfunc(anything,tan),F->InertForm:-Parse( cat("sin(",String(op(1,F)),")/(sqrt(1-sin(",String(op(1,F)),")^2))")));
  else
     error "k must be 1 or -1";
  fi;
  e;
end proc:

expr:=cos(x)+sin(x)+x+tan(2*x)+sec(x)+csc(x)+cot(x)+tan(x)+exp(2*cos(x));

cos(x)+sin(x)+x+tan(2*x)+sec(x)+csc(x)+cot(x)+tan(x)+exp(2*cos(x))

change_to_sin_only(expr,1);

%sqrt(`%+`(1, -`%^`(%sin(x), 2)))+sin(x)+x+`%/`(%sin(`%*`(2, x)), %sqrt(`%+`(1, -`%^`(%sin(`%*`(2, x)), 2))))+`%/`(1, %sqrt(`%+`(1, -`%^`(%sin(x), 2))))+`%/`(1, %sin(x))+`%/`(%sqrt(`%+`(1, -`%^`(%sin(x), 2))), %sin(x))+`%/`(%sin(x), %sqrt(`%+`(1, -`%^`(%sin(x), 2))))+exp(2*%sqrt(`%+`(1, -`%^`(%sin(x), 2))))

change_to_sin_only(expr,-1);

`%*`(-1, %sqrt(`%+`(1, -`%^`(%sin(x), 2))))+sin(x)+x+`%/`(%sin(`%*`(2, x)), `%*`(-1, %sqrt(`%+`(1, -`%^`(%sin(`%*`(2, x)), 2)))))+`%/`(1, `%*`(-1, %sqrt(`%+`(1, -`%^`(%sin(x), 2)))))+`%/`(1, %sin(x))+`%/`(`%*`(-1, %sqrt(`%+`(1, -`%^`(%sin(x), 2)))), %sin(x))+`%/`(%sin(x), `%*`(-1, %sqrt(`%+`(1, -`%^`(%sin(x), 2)))))+exp(2*`%*`(-1, %sqrt(`%+`(1, -`%^`(%sin(x), 2)))))

expr:=1/tan(2*sin(x))+sec(x);

1/tan(2*sin(x))+sec(x)

change_to_sin_only(expr,1);

1/`%/`(%sin(`%*`(2, %sin(x))), %sqrt(`%+`(1, -`%^`(%sin(`%*`(2, %sin(x))), 2))))+`%/`(1, %sqrt(`%+`(1, -`%^`(%sin(x), 2))))

change_to_sin_only(expr,-1);

1/`%/`(%sin(`%*`(2, %sin(x))), `%*`(-1, %sqrt(`%+`(1, -`%^`(%sin(`%*`(2, %sin(x))), 2)))))+`%/`(1, `%*`(-1, %sqrt(`%+`(1, -`%^`(%sin(x), 2)))))

 


 

Download convert_to_sin_v2.mw

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.

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