Maple 18: Integral of modified bessel function - maple

I try to calculate the following integral by Maple 18:
int(BesselK(1, x)/x^3, x);
The result is:
(1/16)*MeijerG([[1], []], [[-1/2, -3/2], [0]], (1/4)*x^2)
However, when I calculate the derivation of the above result, I didn't get the same expression representation:
diff((1/16)*MeijerG([[1], []], [[-1/2, -3/2], [0]], (1/4)*x^2), x)
= (1/8)*MeijerG([[], []], [[-1/2, -3/2], []], (1/4)*x^2)/x
How do I tell Maple to expresse the result by modified bessel function instead of MeijerG function?
Thanks!

restart:
igrand := BesselK(1, x)/x^3;
BesselK(1, x)
igrand := -------------
3
x
sol := int(igrand, x);
1 / [[-1 -3] ] 1 2\
sol := -- MeijerG|[[1], []], [[--, --], [0]], - x |
16 \ [[2 2 ] ] 4 /
dsol := convert( diff(sol,x), StandardFunctions );
/ (1/2)\
| / 2\ |
BesselK\1, \x / /
dsol := ---------------------
3
x
simplify(dsol) assuming x>=0;
BesselK(1, x)
-------------
3
x

Related

is it possible to add an integration rule to Maple int?

I'd like Maple to return ln(abs(x)) for int(1/x,x) instead of ln(x).
Is there a way to give a rule using a pattern, for int to use in this case as it is possible to do in Mathematica? i.e. somehow to override int result for a specific result like the above? Or may be there is some global option one can set?
Maple 2018.1
A procedure way:
REALINT2 := proc (f, x) local func, a;
func := int(f, x);
a := selectfun(func, ln);
`assuming`([simplify(eval(func, [seq(a[k] = map(proc (x) options operator, arrow;
abs(x) end proc, a[k]), k = 1 .. nops(a))]))], [x in real]) end proc:
REALINT2(1+1/x, x);
REALINT2(1/sin(x), x);
REALINT2(x/(x^2+1), x);
REALINT2(tan(x), x);
REALINT2((diff(f(x), x))/f(x), x);
REALINT2(1+1/abs(x), x);
`assuming`([REALINT2(1/x, x)], [x < 0])
# x + ln(|x|)
# ln(1 - cos(x)) - ln(|sin(x)|)
# 1 / 2 \
# - ln\x + 1/
# 2
# -ln(|cos(x)|)
# ln(|f(x)|)
# / x - ln(-x) x < 0
# |
# < undefined x = 0
# |
# \ x + ln(x) 0 < x
# ln(-x)

Maple: specify variable over which to maximize

This is a very simple question, but found surprisingly very little about it online...
I want to find the minimizer of a function in maple, I am not sure how to indicate which is the variable of interest? Let us take a very simple case, I want the symbolic minimizer of a quadratic expression in x, with parameters a, b and c.
Without specifying something, it does minimize over all variables, a, b, c and x.
f4 := a+b*x+c*x^2
minimize(f4, location)
I tried to specify the variable in the function, did not work either:
f5 :=(x) ->a+b*x+c*x^2
minimize(f5, location)
How should I do this? And, how would I do if I wanted over two variables, x and y?
fxy := a+b*x+c*x^2 + d*y^2 +e*y
f4 := a+b*x+c*x^2:
extrema(f4, {}, x);
/ 2\
|4 a c - b |
< ---------- >
| 4 c |
\ /
fxy := a+b*x+c*x^2 + d*y^2 +e*y:
extrema(fxy, {}, {x,y});
/ 2 2\
|4 a c d - b d - c e |
< --------------------- >
| 4 c d |
\ /
The nature of the extrema will depend upon the values of the parameters. For your first example above (quadratic in x) it will depend on the signum of c.
The command extrema accepts an optional fourth argument, such as an unassigned name (or an uneval-quoted name) to which is assigns the candidate solution points (as a side-effect of its calculation). Eg,
restart;
f4 := a+b*x+c*x^2:
extrema(f4, {}, x, 'cand');
2
4 a c - b
{----------}
4 c
cand;
b
{{x = - ---}}
2 c
fxy := a+b*x+c*x^2 + d*y^2 +e*y:
extrema(fxy, {}, {x,y}, 'cand');
2 2
4 a c d - b d - c e
{---------------------}
4 c d
cand;
b e
{{x = - ---, y = - ---}}
2 c 2 d
Alternatively, you may set up the partial derivatives and solve them manually. Note that for these two examples there is just a one result (for each) returned by solve.
restart:
f4 := a+b*x+c*x^2:
solve({diff(f4,x)},{x});
b
{x = - ---}
2 c
normal(eval(f4,%));
2
4 a c - b
----------
4 c
fxy := a+b*x+c*x^2 + d*y^2 +e*y:
solve({diff(fxy,x),diff(fxy,y)},{x,y});
b e
{x = - ---, y = - ---}
2 c 2 d
normal(eval(fxy,%));
2 2
4 a c d - b d - c e
---------------------
4 c d
The code for the extrema command can be viewed, by issuing the command showstat(extrema). You can see how it accounts for the case of solve returning multiple results.

How can I use the return of a MAPLE procedure as a function directly

This may be very basic, but I can't seem to figure it out: I am trying to use the output of a procedure directly as a function. The Procedure is a prefabricated one, namely the dsolve option in MAPLE. Specifically, I would like to say
dsolve({diff(y(t), t) = y(t)*t, y(1) = 1}, y(t), series, t = 1, order = 7)
The result is
y(t) = t+1-1+(t-1)^2+(2/3)*(t-1)^3+(5/12)*(t-1)^4+(13/60)*(t-1)^5+(19/180)*(t-1)^6+O((t-1)^7)
Which is great, but I can't use this as a function directly, i.e., when I type in y(3), I get y(3). I'm sure this is because the procedure is returning a statement instead of a function. I guess the most basic way around this would be to copy and paste the expression and say y:=t-> whatever, but this is inelegant. How can I get around this?
Thank you
Yes, you are getting back an equation of the form y(t)=<some series> from your dsolve call.
dsol := dsolve({diff(y(t), t) = y(t)*t, y(1) = 1}, y(t), series, t = 1, order = 5);
2 2 3 5 4 / 5\
dsol := y(t) = 1 + (t - 1) + (t - 1) + - (t - 1) + -- (t - 1) + O\(t - 1) /
3 12
You can also convert the series structure on the right-hand side of that to a polynomial (ie. get rid of the big-O term).
convert( dsol, polynom );
2 2 3 5 4
y(t) = t + (t - 1) + - (t - 1) + -- (t - 1)
3 12
You can also evaluate the expression you want, y(t), at that equation. (Or you could just use the rhs command. For sets of equations in the multivariable case the eval approach is more robust and straighforward.)
eval( y(t), convert( dsol, polynom ) );
2 2 3 5 4
t + (t - 1) + - (t - 1) + -- (t - 1)
3 12
And, finally, you can also produce an operator from this expression.
Y := unapply( eval( y(t), convert( dsol, polynom ) ), t );
2 2 3 5 4
Y := t -> t + (t - 1) + - (t - 1) + -- (t - 1)
3 12
That operator is a procedure, and can be applied to whatever point you want.
Y(3);
19
The way I have it above, the statement which assigns to Y happens to contain all the individual steps. And that's the only statement above which you'd need to execute, to get the operator that I assigned to Y.If you prefer you could do each step separately and assign each intermediate result to some name. It just depends on whether you want them for any other purpose.
restart:
dsol := dsolve({diff(y(t), t) = y(t)*t, y(1) = 1}, y(t), series, t = 1, order = 5):
peq := convert( dsol, polynom ):
p := eval( y(t), peq ):
Y := unapply( p, t ):
Y(3);
19

Jacobian using in Maple

How can I use the Jacobian written below as function from (x, y) ?
g := (x, y) -> x - y
u := (x, y) -> x^2 + y^2
J := jacobian([g(x, y), u(x, y)], [x, y]);
My idea was to make funcion like this
Jf := (u, v) -> subs(x = u, y = v, J(x, y))
but it returns ugly matrix with brakets inside.
P. S. I use Maple 17
The linalg package (which exports the jacobian command) and lowercase matrix are deprecated. Use LinearAlgebra and Matrix instead, and VectorCalculus:-Jacobian.
Also, note the use of unapply.
restart:
g := (x, y) -> x - y:
u := (x, y) -> x^2 + y^2:
J:=VectorCalculus:-Jacobian([g(x,y),u(x,y)],[x,y]);
[ 1 -1 ]
J := [ ]
[2 x 2 y]
Jf:=unapply(J,[x,y]):
Jf(1,1);
[1 -1]
[ ]
[2 2]
Jf(s,t);
[ 1 -1 ]
[ ]
[2 s 2 t]

Maple, converting from polar to cartesian expression?

In Maple I have a polar expression
and I need to convert it to a Cartesian expression. Though the convert function of Maple doesn't seem to have an option for this.
I currently have a by-hand conversion:
Though there has to be a proper automatic version, isn't there?
Thanks!
The general mechansisms are,
G:=a+b*I;
G := a + I b
H:=convert(G,polar);
H := polar(|a + I b|, argument(a + I b))
evalc(H);
a + I b
So, for your example with given operator specifying the modulus,
r := (theta,a,epsilon) -> a*(1-epsilon^2)/(1+epsilon*cos(theta)):
evalc( polar( r(theta,a,epsilon), theta ) );
/ 2 \ / 2 \
a \-epsilon + 1/ cos(theta) I a \-epsilon + 1/ sin(theta)
---------------------------- + ------------------------------
1 + epsilon cos(theta) 1 + epsilon cos(theta)