## 17907 Reputation

13 years, 194 days

## x>0 is the domain for ln(x)...

@nm  Very often you have to help Maple to achieve your goal. In this example, the assumption  x>0   is natural, since  x>0  is the domain for the function  ln(x)  in the real domain.

## method of undefined coefficients...

@DanishMapleFan  If the polynomials  h  and  g  are given, then you can use the method of undefined coefficients to reduce the problem to solving a system of linear equations.

The same example (without compoly):

```restart;

g:=unapply((x+1)^2, x);
f:=unapply(2*x^2+x+3, x);
h:=expand((f@g)(x));
F:=unapply(a*x^2+b*x+c, x);
Eq:=expand((F@g)(x))=h;

Sys:={seq(coeff(lhs(Eq),x,n)=coeff(rhs(Eq),x,n), n=0..4)};
solve(Sys);
assign(%);

is(F(x)=f(x));
```

## Re...

@nm  I do not understand at all what is the point of applying the  solve  command to a differential equation. Below are two very simple examples (which essentially mean the same thing). The output of the second example seems to me incorrect:

```solve(y(x)+diff(y(x),x)=0, y(x)); # example 1
solve(y(x)+D(y)(x)=0, y(x)); # example 2
```

## Width of legends box...

@AHSAN   depends on the width of the plot and is controlled by Maple automatically (see 2 examples below). Try playing with the options  size  for the plot  and  font  for legends. I don't know how to control  the width of legends box programmatically:

```restart;
v := a+2*H*Q/T;
v := subs(H = T*x, v);

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v)], x = 1 .. 10, style = pointline, colour = [black, red], symbol = [solidcircle, asterisk], symbolsize = 15, axes = boxed, numpoints = 20, legend=["a = 0.1, Q = 0.5 ", "a = 0.2, Q = 0.4"], legendstyle=[location=top],size=[400,400]); #example 1

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v)], x = 1 .. 10, style = pointline, colour = [black, red], symbol = [solidcircle, asterisk], symbolsize = 15, axes = boxed, numpoints = 20, legend=["a = 0.1, Q = 0.5 ", "a = 0.2, Q = 0.4"], legendstyle=[location=top],size=[250,400]); #example 2
```

## Four positions only...

@AHSAN  As you yourself mentioned, only  4 positions are available (in the example below, all the legends on the right). Therefore, if none of these options suits you, then this problem cannot be solved using the  legend  option.

```restart;
v := a+2*H*Q/T;
v := subs(H = T*x, v);

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v), subs(a = 0.3, Q = 0.35, v), subs(a = 0.4, Q = 0.3, v)], x = 1 .. 10, colour = [black, red, blue, green], axes = boxed);

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v)], x = 1 .. 10, style = pointline, colour = [black, red], symbol = [solidcircle, asterisk], symbolsize = 15, axes = boxed, numpoints = 20, legend=["a = 0.1, Q = 0.5", "a = 0.2, Q = 0.4"], legendstyle=[location=right]);```

## A way...

@AHSAN  Below the example of legends for the second plot. The same can be used for the first plot:

```restart;
v := a+2*H*Q/T;
v := subs(H = T*x, v);

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v), subs(a = 0.3, Q = 0.35, v), subs(a = 0.4, Q = 0.3, v)], x = 1 .. 10, colour = [black, red, blue, green], axes = boxed);

plot([subs(a = 0.1, Q = 0.5, v), subs(a = 0.2, Q = 0.4, v)], x = 1 .. 10, style = pointline, colour = [black, red], symbol = [solidcircle, asterisk], symbolsize = 15, axes = boxed, numpoints = 20, legend=["a = 0.1, Q = 0.5", "a = 0.2, Q = 0.4"]);
```

Edit.

## Re...

@tomleslie Thank you! I did not know about it. The good workaround.

## OK...

@lcz  Yes, I know, but this is the simplest solution to the problem for older versions of Maple. I think that this is quite possible to put up with. `3`!  is not calculated because  `3`  is not an integer but just a symbol.

## ?...

@mmcdara  I didn't understand where this error came from. I saved my worksheet again and downloaded it. Everything seems to be working correctly now.

## seq is missed...

@nm  OP just missed the  seq  command when copying.

## Not the final result...

@Preben Alsholm  Thanks for this observation. But this is only an intermediate result (not final one). We want to get the right side of the identity below:

`is(x+y-2*sqrt(x*y)=-(sqrt(-x)+sqrt(-y))^2) assuming negative;`

true

## Wrong solution...

@mmcdara  It doesn't surprise you that

`plots:-implicitplot(g, x = -2..2, y= -2..2);`

doesn't return any plot. Maple is right here, since the equation  g = 0  has no solutions. And here

`[solve(g, y)];`

the command  solve  is not working correctly. It just formally expresses  y  through  x (these formulas can also be obtained manually by sequential squaring) , without worrying about any equivalence. It is very easy to check by simply substituting the found solution into the equation:

```restart;
assume(x::real, y::real):
z := x+I*y:
g := abs(z-I)-abs(z+1)-2;
sol := [solve(g, y)];
simplify(eval(g,y=sol[1]));
simplify(eval(%, x=-1));  # Check - should be 0```

Here's another example with an obvious bug:

```restart;
solve(sqrt(x+y)+sqrt(x-y)=-2);```

I'm going to update my answer below shortly where I explain in detail that there is no solution for the equation

`abs(z-I)-abs(z+1)=2 , where z=x+I*y  for real x and y`

## Re...

@acer  Thanks. There has been some progress after Maple 2018, but some bugs still remain. For some reason, some roots are skipped. In these examples, the  real  option should not be required because inequalities in the real domain are included  x>=-7*Pi/2, x<=-2*Pi   and so on.

## Thanks...

@acer  Thank you.

## How will it be in Maple 2020?...

Maple 2018 easily handles this trivial example as well. But it fails with a slightly complicated example below. I wonder what will happen in Maple 2020?

```restart;
kernelopts(version);

assume(x, 'real'); assume(y, 'real');
verify(x^2 - x*y + y^2, 0, {'greater_equal'});
is(x^2 - x*y + y^2>=0);

restart;
verify(x^2 - x*y + y^2, 0, {'greater_equal'}) assuming x::real, y::real;
is(x^2 - x*y + y^2>=0) assuming x::real, y::real;
```