MaplePrimes Questions

Although I still prefer applyrule (as evalindets/subsindets is not as intuitive as applyrule),  I have heard that it is regarded as being more or less antiquated in modern Maple. I notice that a lot of (yet not all) examples given in the help pages of evalindets/subsindets can be reformulated by applyrule, but does any use of applyrule also correspond to using evalindets/subsindets? And if so, how to equivalently rewrite those transformation rules (especially complicated ones like nested function applications) in the syntax of evalindets/subsindets?

Dear Maple users/ experts

I have three functions, each with two parameters, alpha and delta, changing over 0..1. I want to partition the region in terms of what part gets the highest value. In the attached maple file, I used "implicit plot" and did it for any pair of functions in a reasonable time. But I don't know how these three plots can be consolidated into one. ('inequal' command was not precise while taking too long).  2D_implicitplot_with_three_functions.mw

Hi everyone and happy new year to all.

My question is: Is there a way to change the position of the axes labels in a plot? say, put them at the far end of the axes as some other softwares do. And is there any way to end the axes with arrows?

Axes labels position

kernelopts(version)

`Maple 2021.2, APPLE UNIVERSAL OSX, Feb 1 2022, Build ID 1590019`

(1)

y := proc (x) options operator, arrow; 1/abs(x) end proc

proc (x) options operator, arrow; 1/abs(x) end proc

(2)

plot(y(x), x = -4 .. 4)

 

Download labels.mw

There are things that seem simple but rapidly turn into a nightmare.

Here is an example: what I want is to the expression given at equation (4) in the attached file.

Using Int gives a wrong result.
Using int gives a right one but not of the desired form (some double integrals are nested while others are not).

I've been stuck on this problem for hours, can you please help me to fix it?

TIA

restart

use Statistics in
  # For more generality defina an abstract probability distribution.
  AbstractDistribution := proc(N)
    Distribution(
      PDF = (x -> varphi(seq(x[n], n=1..N)))
    )
  end proc:

  # Define two random variables pf AbstractDistribution type.
  X__1 := RandomVariable(AbstractDistribution(2)):
  X__2 := RandomVariable(AbstractDistribution(2)):

end use;

proc (N) Statistics:-Distribution(Statistics:-PDF = (proc (x) options operator, arrow; varphi(seq(x[n], n = 1 .. N)) end proc)) end proc

 

_R

 

_R0

(1)

F := (U1, U2) -> U1/(U1+U2);
T := mtaylor(F(X__1, X__2), [X__1=1, X__2=1], 2):

proc (U1, U2) options operator, arrow; U1/(U1+U2) end proc

(2)


Error: x[2] is droped out of the double integral in the rightmost term

use IntegrationTools in

J := eval([op(expand(T))], [seq(X__||i=x[i], i=1..2)]);
L := add(
       map(
         j ->  
         if j::numeric then
           j
         else
           (Expand@CollapseNested)(
             Int(
               j * Statistics:-PDF(X__1, x)
               , seq(x[i]=-infinity..+infinity, i=1..2)
             )
           )
         end if
         , J
       )  
     ):
ET := %
end use;

[1/2, (1/4)*x[1], -(1/4)*x[2]]

 

1/2+(1/4)*(Int(x[1]*varphi(x[1], x[2]), [x[1] = -infinity .. infinity, x[2] = -infinity .. infinity]))-(1/4)*x[2]*(Int(varphi(x[1], x[2]), [x[1] = -infinity .. infinity, x[2] = -infinity .. infinity]))

 

1/2+(1/4)*(Int(x[1]*varphi(x[1], x[2]), [x[1] = -infinity .. infinity, x[2] = -infinity .. infinity]))-(1/4)*x[2]*(Int(varphi(x[1], x[2]), [x[1] = -infinity .. infinity, x[2] = -infinity .. infinity]))

(3)


I want this

'ET' = 1/2
       +
       (1/4)*(Int(Int(x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))
       -(1/4)*(Int(Int(x[2]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))

ET = 1/2+(1/4)*(Int(Int(x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))-(1/4)*(Int(Int(x[2]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))

(4)


With int instead of Int one integral is double the other is double-nested

L := add(
       map(
         j ->  
         if j::numeric then
           j
         else
             int(
               j * Statistics:-PDF(X__1, x)
               , seq(x[i]=-infinity..+infinity, i=1..2)
             )
         end if
         , J
       )  
     ):
ET := %

1/2+int(int((1/4)*x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity)+int(-(1/4)*x[2]*(int(varphi(x[1], x[2]), x[1] = -infinity .. infinity)), x[2] = -infinity .. infinity)

(5)


As the expression of ET is now correct, I tried to use IntegrationTools to get the
form I want (equation (4)).

But as soon as I replace int by Int x[2] is again droped out.

So it's not even worth thinking about using CollapseNested!

 

use IntegrationTools in
  eval(ET, int=Int);  
end use;

1/2+Int(Int((1/4)*x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity)+Int(-(1/4)*x[2]*(Int(varphi(x[1], x[2]), x[1] = -infinity .. infinity)), x[2] = -infinity .. infinity)

(6)

 

Download Int_int.mw

Given an expression expr, and symbol, say I wanted to check that only shows as argument to a specific Maple function. In this case, say ln() just an example but this can be any other function.

But if shows up in the expression but not as argument to ln() then I want to detect this also. So the function is passed the expression and the symbol name, and it returns true or false. 

True means the symbol only shows inside ln and false means it found in the expression but not inside ln()

I can find all indets where the symbol shows inside the function. But the problem is how to find if the symbol shows outside of the function?

I think I need to use depends() somehow. But could not figure out how do far. Below is the code I have and few test examples and the result expected.

is_symbol_inside_func_only:=proc(expr::anything,f,y::symbol)::truefalse;
local the_type:=`Or`(     
          'specfunc( `&*`(anything,identical(y)), f )',  
          'specfunc( identical(y), f )'  ,
          'specfunc( `&+`(anything,identical(y)), f )'
          );
local T;
T:=indets(expr, the_type );
print(T);

#need to check that y does not show any where inside expression unless 
#as argument to f

RETURN(true); #or RETURN(false);
end proc:

Here some test cases

expr:=3*ln(1+y)+ln(3*y)*y+ln(y)+cos(7*y);
is_symbol_inside_func_only(expr,ln,y); #should return false

expr:=3*ln(1+y)+ln(3*y);
is_symbol_inside_func_only(expr,ln,y); #should return true

expr:=ln(y)+ln(3*y)+cos(y);
is_symbol_inside_func_only(expr,ln,y); #should return false


expr:=3+cos(y);
is_symbol_inside_func_only(expr,cos,y); #should return true

expr:=y+ln(y);
is_symbol_inside_func_only(expr,ln,y); #should return false

expr:=-1/2*ln(y-1)+1/3*ln(y)+1/6*ln(y-3):
is_symbol_inside_func_only(expr,ln,y); #should return true

some context: I wanted to apply exponential to an expression to convert all ln(y)+ln(1+y)+...  to exp(...) to make it easy to process.

But wanted to do this ONLY if all terms that has are functions on ln otherwise, I will not raise it to exp in this case. The expression will always have the symbol in it. So need to worry about this case. 

Update

After asking the question, I thought about using selectremove and it seems to do what I want. But need to test it more.

is_symbol_inside_func_only:=proc(expr::anything,f,y::symbol)::truefalse;
local the_type:=`Or`(     
          'specfunc( `&*`(anything,identical(y)), f )',  
          'specfunc( identical(y), f )'  ,
          'specfunc( `&+`(anything,identical(y)), f )'
          );
local hasF,nothasF;
hasF,nothasF:=selectremove(hastype,expr,the_type);
if has(nothasF,y) then
   RETURN(false);
else
   RETURN(true);
fi;
end proc:

Here is the result

expr:=3*ln(1+y)+ln(3*y)*y+ln(y)+cos(7*y):
is_symbol_inside_func_only(expr,ln,y); #should return false

expr:=3*ln(1+y)+ln(3*y):
is_symbol_inside_func_only(expr,ln,y); #should return true

expr:=ln(y)+ln(3*y)+cos(y):
is_symbol_inside_func_only(expr,ln,y); #should return false

expr:=3+cos(y):
is_symbol_inside_func_only(expr,cos,y); #should return true

expr:=y+ln(y):
is_symbol_inside_func_only(expr,ln,y); #should return false

expr:=-1/2*ln(y-1)+1/3*ln(y)+1/6*ln(y-3):
is_symbol_inside_func_only(expr,ln,y); #should return true


 

Update

I just found my function has a bug. I added one more test case. so you can ignore my function and use any of the other ones given in the answers below.

 

Maple 2023.2.1

The command "if x+x=2*x then print(1) else print(0) fi" gives the output 1. Similarly for

x*x=x^2. But "if (x+1)^2=x^2+2*x+1 then print(1) else print(0) fi" gives 0. I suppose that this isn't considered a bug, but could someone explain the rationale behind it? How does one get this type of command to behave in what I would consider the intuitive way?

Hi. i want to create a list of n random 0 and 1 numbers with x numbers equal to 1 and n-x number equal to zero.
for example in the code below, i have produced n=100 numbers of 0 and 1. But i want to create a proc that takes x as an input and generates this list with specified number of x numbers 1 and n-x numbers zero randomly. thanks for the help
 

restart:with(RandomTools):

n:=100

100

(1)

A:=[seq](Generate(choose({0, 1})),i=1..n)

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

(2)

 

 

 


 

Download problem.mw

The command

plot(x^(1/3), x = -10 .. 10)

plots only the points where x>=0, as for negative values of x the cubic root retuns only the complex root.

Ca can I modify it so that it returns only the real root, so that the whole plot can be viewed?

Hi,

is there fix for the following quirk in the Maple 2023 editor:

randomly (hours, days) some characters change their appearance like p.e. the = sign becomes d-bold or sigma becomes s-bold. I have never experienced this in previous versions.

Thanks in advance.

Why does  int(x^17*cos(x^6), x) yields the complex form

-(x^12 + 2*I*x^6 - 2)*exp(x^6*I)*I/12 + (x^12 - 2*I*x^6 - 2)*exp(-I*x^6)*I/12

instead of the real (and more straightforward) answer

x^12/6*sin(x^6) + x^6/3*cos(x^6) - sin(x^6)/3

Both are equivalent, and the second form can be achieved from the first one by aplying Euler's identity.

However, how can I force int to yield the second form (real)?

First, this is not a homework assignment.  I am evaluating Maple as a replacement for a paper notebook since I never seem to have one at hand when I want one.  I want to be able to do algebra but seemingly at a finer level of detail than factor, collect, simplify, and expand seem to offer.  Here is what seems like a very simple example that I cannot crack:

(x-a)2-2a(x-a)

should simplify to 

x2 - a2

No matter what try with factor, collect, simplify, sort, and expand, I cannot get it past

x2 - 2xa + a2 + 2a(x - a)

How can I get maple to expand and collect specific terms in an expression?

Hi, maybe someone knows how to fix this:

"Error, (in assuming) when calling 'assume'. Received: 'question.mw'"

I am attaching the corresponding maple file. I've never met such an error message, and unfortunately the Maplesoft help does not contain any information about such an issue : 

restart; (2^(1/2+1/2+1)*GAMMA(n+1/2+1)*GAMMA(n+1/2+1))/((2*n+1/2+1/2+1)*GAMMA(n+1/2+1/2+1)*factorial(n))

4*GAMMA(n+3/2)^2/((2*n+2)*GAMMA(n+2)*factorial(n))

(1)

JacobiP(n, 1/2, 1/2, 1)

JacobiP(n, 1/2, 1/2, 1)

(2)

evalf(JacobiP(3, 1/2, 1/2, 1))

2.187500000

(3)

f := proc (n, x) options operator, arrow; (1/4)*JacobiP(n, 1/2, 1/2, x)*4^(1/2)/(GAMMA(n+3/2)^2/((2*n+2)*GAMMA(n+2)*factorial(n)))^(1/2) end proc

proc (n, x) options operator, arrow; (1/4)*JacobiP(n, 1/2, 1/2, x)*4^(1/2)/(GAMMA(n+3/2)^2/((2*n+2)*GAMMA(n+2)*factorial(n)))^(1/2) end proc

(4)

int(f(1, x)^2*sqrt(-x^2+1), x = -1 .. 1)

1

(5)

int(f(2, x)^2*sqrt(-x^2+1), x = -1 .. 1)

1

(6)

int(f(3, x)^2*sqrt(-x^2+1), x = -1 .. 1)

1

(7)

c := proc (n) options operator, arrow; int(sqrt(1+x)*f(n, x)*sqrt(-x^2+1), x = -1 .. 0)+int(f(n, x)*sqrt(-x^2+1), x = 0 .. 1) end proc

proc (n) options operator, arrow; int(sqrt(1+x)*f(n, x)*sqrt(-x^2+1), x = -1 .. 0)+int(f(n, x)*sqrt(-x^2+1), x = 0 .. 1) end proc

(8)

c(12)

(2/450225)*(-208+679*2^(1/2))/Pi^(1/2)

(9)

S := proc (N, x) options operator, arrow; evalf(sum(c(n)*f(n, x), n = 0 .. N)) end proc

proc (N, x) options operator, arrow; evalf(sum(c(n)*f(n, x), n = 0 .. N)) end proc

(10)

S(1, 1)

Error, (in assuming) when calling 'assume'. Received: 'contradictory assumptions'

 

NULL

Download question.mw

https://www.maplesoft.com/support/help/errors/view.aspx?path=Error,%20(in%20assuming)%20when%20calling%20%27assume%27.%20Received%3A%20%27contradictory%20assumptions%27

Many thanks in advance

> ode_sys:=2*diff(x(t),t$2) + 6*x(t) - 2*y(t) = 0, diff(y(t),t$2) + 2*y(t) - 2*x(t) = 0:
> lsol:=inttrans:-laplace({ode_sys},t,s)

The displayed output has an unresolved  "=  inttrans/laplace`(0, t, s)" on the end.

> lsol

Does not. Why?

A general term for this series is+-xr, having a positive sign when r is even and a negative sign when r is odd.

​​​​Now because (-1) is positive when r is even and negative when r is odd, the general term can be written as (-1)rxr

Hence;

1-x+x2-x3+...=£or=0(-1)r(x)r

Why does fsolve(x - (-8.0)^(1/3), x) returns only the first root (1.000000000 + 1.732050807*I)  of the polynomial (which clearly has 3 roots)?

First 21 22 23 24 25 26 27 Last Page 23 of 2308