Maple 2022 Questions and Posts

These are Posts and Questions associated with the product, Maple 2022

I need to count how many times a special function shows up in an expression.

The problem is that indets returns a set. So if the same function shows up more than one time in the original expression, with same arguments, only one of these will show up in the result. So I would not know if there were mmore than one of these.

Here is a simple example, using sin(x) here.

restart;
expr:=sin(x)+3*cos(x)*sin(x)+1/sin(2*x);
indets(expr,'specfunc(anything,sin)')

#gives
#   {sin(x), sin(2*x)}

So when I do nops() on the above, it gives 2 and not 3.

How to obtain number of times a function shows in an expression, even it if is repeated?

Hi everyone, I have copied soem code from a paper. I hope to try and manupiluate some of the varables. However it seems while I am coping the code I get this error Error, (in dsolve/numeric/process_input) system must be entered as a set/list of expressions/equations .I have checked online but it seems that there is nothing I can find to fix this problem. My code is posted below 

Thanks for your time and help!

restart

with(VariationalCalculus)

with(ODEtools)

Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received ODEtools

 

with(DEtools)

with(plots); with(plottools); PDEtools[declare]((theta, phi, psi)(t), prime = t)

`derivatives with respect to`*t*`of functions of one variable will now be displayed with '`

(1)

with(linalg)

We will now declare our first equations

 

 

x[1] := l[1]*sin(theta(t))

y[1] := -l[1]*cos(theta(t))``

x[2] := -l[2]*sin(theta(t)); y[2] := l[2]*cos(theta(t))

x[4] := x[1]-l[4]*sin(theta(t)+phi(t)); y[4] := y[1]+l[4]*cos(theta(t)+phi(t)); x[3] := x[2]+l[3]*sin(theta(t)-psi(t)); y[3] := y[2]-l[3]*cos(theta(t)-psi(t))

R[1] := vector(2, [x[1], y[1]]); R[2] := vector(2, [x[2], y[2]]); R[4] := vector(2, [x[4], y[4]]); R[3] := vector(2, [x[3], y[3]])

`\`R`[1]*` ≔ map`(diff, R[1], t); `\`R`[2]*` ≔ map`(diff, R[2], t); `\`R`[4]*` ≔ map`(diff, R[4], t); `\`R`[3]*`≔map`(diff, R[3], t)

NULL

NULL

T := combine(simplify(collect((1/2)*m[1]*innerprod(`\`R`[4]*`,`*R[4]*`)+m[2]/2*
innerprod(\`R[3]\`,\`R[3]`), [l[1], l[2], l[3], l[4], m[1], m[2], diff(theta(t), t), diff(phi(t), t), diff(psi(t), t), cos(psi(t)), sin(psi(t))])), trig)

NULL

U := collect(simplify(expand(g*m[1]*y[4]+g*m[2]*y[3])), [l[1], l[2], l[3], l[4], m[1], m[2], diff(theta(t), t), diff(phi(t), t), diff(psi(t), t), cos(psi(t)), sin(psi(t)), g])

NULL

L := simplify(collect(T-U, [l[1], l[2], l[3], l[4], m[1], m[2], diff(theta(t), t), diff(phi(t), t), diff(psi(t), t), cos(psi(t)), sin(psi(t))]))

NULL

NULL

NULL

Eul := remove(has, EulerLagrange(L, t, [theta(t), phi(t), psi(t)]), K[1]); eq1 := op(select(has, Eul, (diff(psi(t), t))^2)); eq2 := op(select(has, remove(has, Eul, (diff(psi(t), t))^2), sin(psi(t)))); eq3 := op(remove(has, remove(has, Eul, (diff(psi(t), t))^2), sin(psi(t))))

NULL

NULL

INITS := {phi(0) = (1/4)*Pi, psi(0) = (1/4)*Pi, theta(0) = 3*Pi*(1/4), (D(phi))(0) = 0, (D(psi))(0) = 0, (D(theta))(0) = 0}

NULL

PARAM := [g = 9.8, l[1] = 10, l[2] = 100, l[3] = 100, l[4] = 21, m[1] = 1000, m[2] = 1]

NULL

sys := eval([eq1, eq2, eq3], PARAM)

NULL

sol := dsolve([op(sys), op(INITS)], numeric, output = listprocedure)

Error, (in dsolve/numeric/process_input) system must be entered as a set/list of expressions/equations

 

NULL``

 

 

NULL

NULL

``

Download Test_1.mw

Hi, everyone! I am a new user to maple and I need to import some code I have found from a paper, just so I can manupluate some of the variables. However when I have copied and pasted my code, I keep getting the error Error, mismatched or missing bracket/operator.  I did check online and it seems to be a bracket missing but I have copied without errors from the source. 

I have attached a picture and did a copy paste of the code that is giving me an error below. 

Thanks for your help 

x[1] := l[1]*sin(theta(t));
y[1] := -l[1]*cos(theta(t));

x[2] := -l[2]*sin(theta(t));
y[2] := l[2]*cos(theta(t));
R[1] := vector(2, [x[1], y[1]]);
R[2] := vector(2, [x[2], y[2]]);
'R[1]'':=map(diff,R[1],t):

 

restart;

pde := diff(u(x,t),t) + u(x,t)*diff(u(x,t),x) = 0;

diff(u(x, t), t)+u(x, t)*(diff(u(x, t), x)) = 0

These are all wrong:

pdsolve({pde,u(x,0)=f(x)});
pdsolve({pde,u(x,0)=sin(x)});
pdsolve({pde,u(x,0)=erf(x)});

u(x, t) = 0

u(x, t) = 0

u(x, t) = 0

But these ones are correct:

pdsolve({pde,u(x,0)=exp(x)});
pdsolve({pde,u(x,0)=x});

u(x, t) = LambertW(t*exp(x))/t

u(x, t) = x/(t+1)

Download mw.mw

in a worksheet, typing

r:=(x^2 - 2*x - 1)/4;

Maple returns

But when typing

r:=(x^2 - 2*x - 1)/(4*x);

Now it does not expand terms and gives what is expected

Is there a way to make the first example remain unexpanded? Same with Mathematica:

I know this only affects the display only. But it is annoying, as I want to see the numerator and denominator on the screen as I put them there and not have them change.

I tried changing the typesetting level, but this had no effect.

I used to like Maple becuase it does not change anything unless asked to, and everything is explicit, which is better.

Now I am starting to change my mind on this aspect of Maple.

How should I handle the limit in the integration answe?. I don't see why it is necessary.

restart

_local(gamma)

p := `assuming`([proc (alpha) options operator, arrow; alpha^m end proc], [m]); LinearAlgebra:-Transpose(integer)

integer

q := `assuming`([proc (alpha) options operator, arrow; alpha^n end proc], [n]); LinearAlgebra:-Transpose(integer)

integer

Sa := eval((1/2)*(int(simplify(p(alpha)*(D(q))(alpha)), alpha = 0 .. 1)))

-(1/2)*(limit(alpha^(m+n), alpha = 0, right)-1)*n/(m+n)

s1 := eval((1/2)*(int(simplify(p(alpha)*(D(q))(alpha)), alpha)))

(1/2)*alpha^(m+n)*n/(m+n)

eval(s1, alpha = 1)-(eval(s1, alpha = 0))

(1/2)*n/(m+n)

NULL

Download Q_9-9-22_limit_in_integral.mw

Is there an assumption or some other way I can tell Maple to avoid such errors when using odetest, as I get many of them.

I think the solution Maple gives is correct. But odetest generates these strange innternal error that it does not know the sign of a complex number.

restart;
ode:=x^2*diff(y(x), x$2) + (cos(x)-1)*diff(y(x), x) + exp(x)*y(x) = 0;
sol:=dsolve(ode,y(x),series):
odetest(sol,ode,series,point=0);

Error, (in odetest/series) need to determine the sign of I*3^(1/2)

I've seen such error many times before and it is still not fixed in release after release.

I am using Maple 2022.1 on windows 10.

Hi ---

      I know how to add the Angstrom symbol to a plot's axis label using my mouse and the palette menu.  How can I add the Angstroms symbol programmatically to the plot command?  Thanks!

David

Hello,

I have a nonlinear system of 12 SYMBOLIC equations in 6 variables. I am using solve() but it's taking me ages and will probably return the "Kernel connection has been lost" error after a half-day/ a day.

How do I solve it? Is it even possible to solve it? Is there a way to solve it approximately?

Thanks

I would like to insert a hyperling to a geogebra document but the hyperlink box deosn't appear to allow general files. Can this be done?

This is a much simplified version of a problem I am seeing. I think I have to remove all the coerce code I added as it seems to have problems.

Made an object with constructor that take an optional argument. These optional arguments use coerce to convert different types on one type of list.

I have another proc foo() that is called with these arguments, also same optional ones, and it then creates the object passing these arguments to it. 

The problem is that if foo() is called with an optional argument itself, which will default to empty list [], I am not able to create the object now, when doing  ':-ic'=ic  since debugger gives 

Error, invalid input: too many and/or wrong type of arguments passed to ModuleCopy; first unused argument is [] = []

Even though I made sure to pass the optional argument using  ':-name'=value.

The strange thing is that this only shows in the debugger. i.e. when typing the command in the debugger window. But in my application, it does not work inside the debugger and outside since it is much more complicated setup.  This is the simplest example I could make to show the same error in the debugger.

A small example will show the problem.

restart;
A:=module()
   option object;
   export ode;
   export ic;

   export ModuleCopy::static:=proc(_self, proto::A, ode::`=`,
                    { ic::coerce( (ic::list(`=`))->ic, 
                                  (ic::set(`=`))->[ic[]],
                                  `:-NoUserValue`):=[]
                    },$)
        print("ode=",ode);
        print("ic=",ic);
    end proc;
end module;

foo:=proc(ode::`=`,{ ic::coerce( (ic::list(`=`))->ic, 
                     (ic::set(`=`))->convert(ic,list),
                     `:-NoUserValue`):=[]
                    },$)
    local o;
    DEBUG();
    o:=Object(A,ode,':-ic'=ic);
end proc:

# and now

foo(diff(y(x),x)=1)

Now the debugger window shows at the line above just before calling the object constructor. This is what happens next

 

But if I click continue it does not produce an error and actually works. (in my main application, with similar setup, it gives an exception).

If I can figure why debugger gives this error, may be that will help me figure my more complicated setup.  I know if I do not use coerce, the debugger error goes away. Here is a version without coerce, and it works

restart;
A:=module()
   option object;
   export ode,ic;
   export ModuleCopy::static:=proc(_self, proto::A, ode::`=`, { ic::list(`=`):=[] })
        print("ode=",ode);
        print("ic=",ic);
    end proc;
end module;
                  A := Object<<2457889631168>>

foo:=proc(ode::`=`, { ic::list(`=`):=[]})
    local o;
    DEBUG();
    o:=Object(A,ode,':-ic'=ic);
end proc:

#now do
foo(diff(y(x),x)=1)

Now the debugger window comes up, but now see the difference:

 

No error!  even though  `ic` was [] in this case also, like the first example.

So for now, I will remove all the coerce code just to get my application to work again even though I like it, but it seems to cause a problem.

question: What the first example above given an error in the debugger?  

Notice this error only shows up when using a module of type object

Update

This is just to confirm that removing the coerce API and replacing it back as it was with traditional optional arguments as in the second example above the exception went away.  My code is way too large to post here, but that is the only difference I have.  I think there is a problem using coerce with Object constructor calling somewhere.  But I am OK now, and able to continue work.

I have a long description that contains some Maple commands.
I dont want to use # as the lines dont show up when i use

Isee:=proc(a)
    interface(verboseproc = 3);
    printf("%P", eval(a));
end proc

The long description is. Any way around the problem?  

Test:=proc(A,B,C)  description  "Computes projective line through 2 projective points or intersert of 2 projective lines as a projective point or coincidence of piont  line   
 Does some checking on validity of inputs.   
Mobposn:- Global Variable, must = 1 or 3. 
Points are returned as <1,x,y> or <x,y,1>   
 Lines are returned as <z,x,y> or <x,y,z>,  
normalgpt :- Global Variable must be 0 or 1. 
Points with algecraic elements are not reduced to <1,x,y> or <x,y,1> if 0  
 Points are defined as row vectors and  lines as column `vectors"`; 

 print(A,B,A-C); 

 end proc;

I need to conver 2D points to projective points. Originally I used lists but now need to handle vectors too. To add to that that the projective coordinate for points is now being stated as [1,x,y] instead of [x,y,1]. That is was easy enough to handle for lists.

I have a lot of old worksheets that use the list form [x,y,1] that I want to maintain compatibility with. I only have one procedure I need to convert.
 

Mobposn := 1;
testP := [2, 7];
if Mobposn = 1 then
    [1, op(testP)];
else
    [op(testP), 1];
end if;

I need to do the same for vector definition of the points. The points are defined as row Vectors

A:=<2,7>^%T

to get

Ap:=<1,2,7>^%T

or

Ap:=<2,7,1>^%T

I know coud just do (as these are short vectors)
 

Ap:=<1,A_1,A_2>^%T

or
Ap:=<A_1,A_2,1>^%T

Is there a more general way?

Hello,

I'm trying to draw the basins of attraction for King's method with f(z) = z^3 - 1 

Thank you in Advance

I have the following expression:

q1:=2.800000000*10^(-30)*a+2.7800000000*10^(-29)*b+2.7800000000*10^(-31)+3.0*10^(-21)+2.*10^(-32)*c+3.*10^(-30)*d;

I saved it as a string, but the format seems to have changed.

q2:=convert(q1,string)

Can I output it as follows:

"2.800000000*10^(-30)*a+2.7800000000*10^(-29)*b+2.7800000000*10^(-31)+3.0*10^(-21)+2.*10^(-32)*c+3.*10^(-30)*d"
First 29 30 31 32 33 34 35 Last Page 31 of 39