How to simplify matrix in terms of an equation - maxima

I have an matrix in Maxima, let´s say (for simplification of the problem):
A: matrix([2*(a^2+b^2+c^2)])
But I know that:
a^2+b^2+c^2 = 1
How do I simplify that matrix in Maxima in terms of that equation, in order to obtain A = [2]?

I found the solution:
A: matrix([2*(a^2+b^2+c^2)]);
eq: a^2+b^2+c^2 = 1;
scsimp(A, eq);

You can use tellrat.
(%i1) A:matrix([2*(a^2+b^2+c^2)])
(%o1) [ 2 2 2 ]
[ 2 (c + b + a ) ]
(%i2) a^2+b^2+c^2 = 1
2 2 2
(%o2) c + b + a = 1
(%i3) solve(%,a^2)
2 2 2
(%o3) [a = (- c ) - b + 1]
(%i4) tellrat(%[1])
2 2 2
(%o4) [c + b + a - 1]
(%i5) algebraic:true
(%o5) true
(%i6) rat(A)
(%o6)/R/ [ 2 ]
(%i7) untellrat(a)
(%o7) []

Related

Taylor series expansion in maxima

How to expand taylor series/polynomials about Q=0 , and then extract coefficients as a list
example :
taylor ( (sin(q)), q, 0, 9); //taylor expansion for first 9 terms gives the next line
(%o1)/T/ q\-q^3/6+q^5/120\-q^7/5040+q^9/362880+...
then using coeff ((%o1), q ^n); gives me the coefficient at n only, what i want is a list for all the coefficients of that expression
Try coeff plus makelist, e.g. something like: makelist(coeff(%o1, q, n), n, 0, 9);
Edit:
I see now that I misread your question and there is already an answer. Nevertheless I will keep it because it is related to your question.
Use powerseries instead of taylor:
(%i1) expr:powerseries(sin(x),x,0);
inf
==== i2 2 i2 + 1
\ (- 1) x
(%o1) > -----------------
/ (2 i2 + 1)!
====
i2 = 0
You can access the coefficient by the args or part function
(%i2) op(expr);
(%o2) sum
(%i3) args(expr);
i2 2 i2 + 1
(- 1) x
(%o3) [-----------------, i2, 0, inf]
(2 i2 + 1)!
(%i4) part(expr,1);
i2 2 i2 + 1
(- 1) x
(%o4) -----------------
(2 i2 + 1)!
(%i5) args(expr)[1];
i2 2 i2 + 1
(- 1) x
(%o5) -----------------
(2 i2 + 1)!
If you want to change the index variable:
(%i6) niceindices(expr),niceindicespref=[n];
inf
==== n 2 n + 1
\ (- 1) x
(%o6) > ---------------
/ (2 n + 1)!
====
n = 0

Performing Laplace transform on non-continuous function in Maxima

I am calculating the following function's Laplace transform, but I get some strange output with limit and realpart etc on (%t5) and (%t6). What I expect is something like a_n = 0 and b_n = -1/(n*%pi).
Why is this happening? Am I defining the function at (%i1) incorrectly? Or is this a limitation of Maxima?
(%i1) f(t) := mod(t, 1);
(%o1) f(t) := mod(t, 1)
(%i2) plot2d(f(t), [t, -2, 2]);
(%o2) [/tmp/maxout1266174.gnuplot_pipes]
(%i3) load(fourie);
(%o3) /usr/share/maxima/5.43.0/share/calculus/fourie.mac
(%i4) fourier(f(t), t, 1);
1
(%t4) a = -
0 2
/
[
(%t5) a = limit I cos(%pi n t) realpart(floor(t)) dt
n t -> - 1 ]
/
/
[
- limit I cos(%pi n t) realpart(floor(t)) dt
t -> 1 ]
/
/
[
(%t6) b = (- limit I sin(%pi n t) realpart(floor(t)) dt)
n t -> 1 ]
/
/
[ 2 sin(%pi n) 2 cos(%pi n)
+ limit I sin(%pi n t) realpart(floor(t)) dt + ------------ - ------------
t -> - 1 ] 2 2 %pi n
/ %pi n
(%o6) [%t4, %t5, %t6]
(%i7)

Substitute variable in Maxima

newbie Maxima question
I have a transfer function in Maxima
E1 : y = K_i*s/(s^2 + w^2);
I'd like to have the closed-form of the equation affter applying the bilinear transform
E2 : s = (2/Ts*(z-1)/(z+1));
I would like to get the transfer function for z, by substituing s by equation E2. How should I proceed?
Regards
Note that subst can apply one or more substitutions stated as equations. In this case, try subst(E2, E1).
That will probably create a messy result -- you can simplify it somewhat by applying ratsimp to the result.
Here's what I get from that.
(%i2) E1 : y = K_i*s/(s^2 + w^2);
K_i s
(%o2) y = -------
2 2
w + s
(%i3) E2 : s = (2/Ts*(z-1)/(z+1));
2 (z - 1)
(%o3) s = ----------
Ts (z + 1)
(%i4) subst (E2, E1);
2 K_i (z - 1)
(%o4) y = ------------------------------
2
4 (z - 1) 2
Ts (z + 1) (------------ + w )
2 2
Ts (z + 1)
(%i5) ratsimp (%);
2
2 K_i Ts z - 2 K_i Ts
(%o5) y = -----------------------------------------------
2 2 2 2 2 2 2
(Ts w + 4) z + (2 Ts w - 8) z + Ts w + 4

Maxima: How to factor a expression in an expected form

I have an expression:
(b+2*ab+a+1)/c
I want to use Maxima to factor the equation treating (b+1) as a factor.
i.e. I want the expression in the following form:
[(b+1)(1+a)+ab]/c
Any help would be appreciated.
Well, my advice is first isolate the numerator, then get the quotient and remainder after dividing by b + 1, then put the pieces back together.
(%i1) display2d : false $
(%i2) expr : (b + 2*a*b + a + 1)/c $
(%i3) num (expr);
(%o3) 2*a*b+b+a+1
(%i4) divide (num (expr), b + 1);
(%o4) [2*a+1,-a]
(%i5) first(%o4) * (b + 1) + second(%o4);
(%o5) (2*a+1)*(b+1)-a
(%i6) (first(%o4) * (b + 1) + second(%o4)) / denom (expr);
(%o6) ((2*a+1)*(b+1)-a)/c
(%i7) is (equal (%o6, expr));
(%o7) true
Note that divide returns two values; first is the quotient and second is the remainder.

symbolically replace expressions in maxima

I'm having trouble finding out how to do this:
x=a+b
y=c+d
z=x*y
I would like the output to be
z=ac+ad+bc+bd
not
z=xy
Like this?
(%i1) x: a+b;
(%o1) b + a
(%i2) y: c+d;
(%o2) d + c
(%i3) z: x*y;
(%o3) (b + a) (d + c)
(%i4) z: expand (z);
(%o4) b d + a d + b c + a c
(%i5)
Assignment in maxima is done by :, not = (which is used for checking for equality)
Actually, to get the output he's requesting without assigning a lot of variables,
you can just do this:
(%i1) z = x*y, x = a+b, y = c+d, expand;
(%o1) z = b d + a d + b c + a c
This is an old question, but the canonical solution in my opinion is the subst() function

Resources