Maple basic: transform the maple results - maple

I was running diff(abs(2*x + 5), x), maple gives me an answer of 2*abs(1, 2*x + 5)
I actually dont know what that means. But I know the answer is (4*x + 10)/abs(2*x + 5). How could I transform the answer from 2*abs(1, 2*x + 5) to (4*x + 10)/abs(2*x + 5)
Thanks for the help.

diff(abs(2*x + 5), x) assuming x::real;
/ 5\
2 signum|x + -|
\ 2/
ans1 := normal(convert(%,abs));
2 x + 5
ans1 := -------
| 5|
|x + -|
| 2|
ans2 := (4*x + 10)/abs(2*x + 5);
4 x + 10
ans2 := ---------
|2 x + 5|
combine(normal(convert(ans1-ans2, signum)));
0
The meaning of abs(1,x) is described on the Help page for the abs command.

Related

kdb union join (with plus join)

I have been stuck on this for a while now, but cannot come up with a solution, any help would be appriciated
I have 2 table like
q)x
a b c d
--------
1 x 10 1
2 y 20 1
3 z 30 1
q)y
a b| c d
---| ----
1 x| 1 10
3 h| 2 20
Would like to sum the common columns and append the new ones. Expected result should be
a b c d
--------
1 x 11 11
2 y 20 1
3 z 30 1
3 h 2 20
pj looks to only update the (1,x) but doesn't insert the new (3,h). I am assuming there has to be a way to do some sort of union+plus join in kdb
You can take advantage of the plus (+) operator here by simply keying x and adding the table y to get the desired table:
q)(2!x)+y
a b| c d
---| -----
1 x| 11 11
2 y| 20 1
3 z| 30 1
3 h| 2 20
The same "plus if there's a matching key, insert if not" behaviour works for dictionaries too:
q)(`a`b!1 2)+`a`c!10 30
a| 11
b| 2
c| 30
got it :)
q) (x pj y), 0!select from y where not ([]a;b) in key 2!x
a b c d
--------
1 x 11 11
2 y 20 1
3 z 30 1
3 h 2 20
Always open for a better implementation :D I am sure there is one.

Get subexpression strings from output of pretty() in MATLAB

Is there a good way to get all the subexpressions in the output of a pretty() call in single-line strings? subexpr() returns a single subexpression, but I'd like to get all of them. Here's what pretty() returns:
syms x
s = solve(x^4 + 2*x + 1, x,'MaxDegree',3);
pretty(s)
/ -1 \
| |
| 2 1 |
| #2 - ---- + - |
| 9 #2 3 |
| |
| 1 #2 1 |
| ---- - #1 - -- + - |
| 9 #2 2 3 |
| |
| 1 #2 1 |
| #1 + ---- - -- + - |
\ 9 #2 2 3 /
where
/ 2 \
sqrt(3) | ---- + #2 | 1i
\ 9 #2 /
#1 == ------------------------
2
/ sqrt(11) sqrt(27) 17 \1/3
#2 == | ----------------- - -- |
\ 27 27 /
Here's what I'd like:
#1 == sqrt(3) ((2/(9 #2)) + #2) 1i) / 2
#2 == (sqrt(11) sqrt(27) / 27 - 17 / 27) ^ (1/3)
That way the output is easy cut-and-pastable into an editor for rapid conversion to code.
MATLAB functions ccode (or matlabFunction) do the trick beautifully.
syms x
s = solve(x^4 + 2*x + 1, x,'MaxDegree',3);
ccode(s, 'file', 'outfile.c');
Matlab generates outfile.c with sparse matrix notation and substitution-simplified computation:
t2 = sqrt(1.1E1);
t3 = sqrt(2.7E1);
t4 = t2*t3*(1.0/2.7E1);
t5 = t4-1.7E1/2.7E1;
t6 = 1.0/pow(t5,1.0/3.0);
t7 = pow(t5,1.0/3.0);
t8 = sqrt(3.0);
t9 = t6*(2.0/9.0);
t10 = t7+t9;
t11 = t6*(1.0/9.0);
A0[0][0] = -1.0;
A0[1][0] = t6*(-2.0/9.0)+t7+1.0/3.0;
A0[2][0] = t7*(-1.0/2.0)+t11-t8*t10*5.0E-1*sqrt(-1.0)+1.0/3.0;
A0[3][0] = t7*(-1.0/2.0)+t11+t8*t10*5.0E-1*sqrt(-1.0)+1.0/3.0;

Some Boolean Algebra Simplication basic

I wanna ask some basic law of boolean algebra.
What i learn is :
1. A+A'B=A+B
2. A+AB'=A+B'
3. A+AB=A
4. A+A'B'=A+B'
but i meet some condition like :
A'+AB
so, what is the answer for A'+AB?
Let's say A' = D so when A is false, then D is true and vice versa.
Then A' + AB = D + D'B and if you understand your first equation:
D + D'B = D + B = A' + B
Regarding your comment:
I'll use this equality: AB + A'B = B and I will combine the first with the third and the second with the fifth term:
x'y'z'+x'yz+xy'z'+xy'z+xyz = y'z' + yz + xy'z
Now, from the result, I can do this:
y'z' + yz + xy'z = yz + y'(z' + zx)
and now, using using A' + AB = A' + B:
yz + y'(z' + zx) = yz + y'(z' + x) = yz + y'z' + y'x
or do this:
y'z' + yz + xy'z = y'z' + z(y+ xy') = y'z' + z(y + x) = y'z' + zy + xz
Are they different? No, take a look at this:
x y z | yz + y'z' + y'x | y'z' + zy + xz
0 0 0 | 1 | 1
0 0 1 | 0 | 0
0 1 0 | 0 | 0
0 1 1 | 1 | 1
1 0 0 | 1 | 1
1 0 1 | 1 | 1
1 1 0 | 0 | 0
1 1 1 | 1 | 1
You can use this open source project to solve basic boolean expression, its solve all the basic boolean expression

Maple 17: Why doesn't series(...,n) always return a series expansion of order n?

In the following example, why does the first series(f,n=infinity,9); return a series of order 8, but it returns a series of order 9 only after executing series(f,n=infinity,10);?
|\^/| Maple 17 (X86 64 LINUX)
._|\| |/|_. Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2013
\ MAPLE / All rights reserved. Maple is a trademark of
Waterloo Maple Inc.
| Type ? for help.
> f := 1 + (n-1)*6/n^3 - (1+6/n^3)^(n-2) * (1+6/n^3/(1+(n^2/2)*6/n^3));
6 (n - 1) / 6 \(n - 2) / 6 \
f := 1 + --------- - |1 + ----| |1 + ------------|
3 | 3 | | 3 |
n \ n / \ n (1 + 3/n)/
> series(f,n=infinity,8);
198 810 1
--- - --- + O(----)
6 7 8
n n n
> series(f,n=infinity,9);
198 810 1
--- - --- + O(----)
6 7 8
n n n
> series(f,n=infinity,10);
198 810 2952 11070 1
--- - --- + ---- - ----- + O(---)
6 7 8 9 10
n n n n n
> series(f,n=infinity,9);
198 810 2952 1
--- - --- + ---- + O(----)
6 7 8 9
n n n n
The third paragraph in the Description section of the help-page for the series command mentions that the order parameter specifies the truncation order for the calculation and is not necessarily the order of the returned series.
Also, there is a remember table in play, so that a higher order returned result may be quickly truncated when a subsequent lower truncation order query is computed. (The Order environment variable is being treated somewhat analogously to the Digits environment variable, in that better or more accurate saved results might be truncated/rounded quickly when a coarser query is made.)
After requesting clearance of a remember table for series, the lower order query must once more be actually computed (using the specified truncation order of the calculation) rather than merely looked up and truncated.
restart:
kernelopts(version);
Maple 17.02, X86 64 WINDOWS, Sep 5 2013, Build ID 872941
f := 1 + (n-1)*6/n^3 - (1+6/n^3)^(n-2) * (1+6/n^3/(1+(n^2/2)*6/n^3)):
series(f,n=infinity,9);
198 810 /1 \
--- - --- + O|--|
6 7 | 8|
n n \n /
series(f,n=infinity,10);
198 810 2952 11070 / 1 \
--- - --- + ---- - ----- + O|---|
6 7 8 9 | 10|
n n n n \n /
series(f,n=infinity,9);
198 810 2952 /1 \
--- - --- + ---- + O|--|
6 7 8 | 9|
n n n \n /
forget(series);
series(f,n=infinity,9);
198 810 /1 \
--- - --- + O|--|
6 7 | 8|
n n \n /

how to expand (cross-multiply) two taylor polynomials in maple 13

> eq1 := taylor(exp((1/2)*lambda*gamma*B), lambda = 0, 3);
print(`output redirected...`); # input placeholder
1 1 2 2 2 / 3\
1 + - gamma B lambda + - gamma B lambda + O\lambda /
2 8
> eq2 := taylor(exp((1/2)*lambda*A), lambda = 0, 3);
print(`output redirected...`); # input placeholder
1 1 2 2 / 3\
1 + - A lambda + - A lambda + O\lambda /
2 8
> eq3 := eq1*eq2;
print(`output redirected...`); # input placeholder
/ 1 1 2 2 2 / 3\\ / 1
|1 + - gamma B lambda + - gamma B lambda + O\lambda /| |1 + - A lambda
\ 2 8 / \ 2
1 2 2 / 3\\
+ - A lambda + O\lambda /|
8 /
> expand(eq1, eq2);
print(`output redirected...`); # input placeholder
1 1 2 2 2 / 3\
1 + - gamma B lambda + - gamma B lambda + O\lambda /
2 8
> expand(eq3);
print(`output redirected...`); # input placeholder
/ 1 1 2 2 2 / 3\\ / 1
|1 + - gamma B lambda + - gamma B lambda + O\lambda /| |1 + - A lambda
\ 2 8 / \ 2
1 2 2 / 3\\
+ - A lambda + O\lambda /|
8 /
> expand(eq1*eq2);
print(`output redirected...`); # input placeholder
/ 1 1 2 2 2 / 3\\ / 1
|1 + - gamma B lambda + - gamma B lambda + O\lambda /| |1 + - A lambda
\ 2 8 / \ 2
1 2 2 / 3\\
+ - A lambda + O\lambda /|
8 /
Hi.. not at all sure if the above will make sense.. (I`d put this text at the top of the question, instead of code first, but the formating does strange things)
Im (trying to) use maple 13 (its what I have access to) to expand two taylor polynomials. and it isnt working. Im sure there must be some simple command I can use, but I haven`t found it. I have also tried a few of these possibilities: http://www.maplesoft.com/support/help/Maple/view.aspx?path=expand . perhaps you folks can help?
You need to convert those two series data structures eq1 and eq2 to polynomials before you can add them or expand their product.
eq1 := taylor(exp((1/2)*lambda*gamma*B), lambda = 0, 3):
eq2 := taylor(exp((1/2)*lambda*A), lambda = 0, 3):
p1:=convert(eq1,polynom):
p2:=convert(eq2,polynom):
p1+p2;
expand(p1*p2);