Substitute variable in Maxima - 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

Related

Why is Maxima failing to give a solution?

I have a function in Maxima I am differentiating then attempting to find the value at which this is zero. When I use solve(), however, I am not given a solution. Why is this, and how can I work around it?
(%i1) f(x):=(-5*(x^4+5*x^3-3*x))/(x^2+1);
(%o1) f(x):=((-5)*(x^4+5*x^3+(-3)*x))/(x^2+1)
(%i2) df(x):=''(diff(f(x), x));
(%o2) df(x):=(10*x*(x^4+5*x^3-3*x))/(x^2+1)^2-(5*(4*x^3+15*x^2-3))/(x^2+1)
(%i3) solve(df(x), x);
(%o3) [0=2*x^5+5*x^4+4*x^3+18*x^2-3]
The function solve is not too strong; there are many problems it can't solve. A stronger version is under development. In the meantime, try the add-on package to_poly_solve. Here's what I get:
(%i1) df(x) := (10*x*(x^4+5*x^3-3*x))/(x^2+1)^2-(5*(4*x^3+15*x^2-3))/(x^2+1) $
(%i2) load (to_poly_solve) $
(%i3) to_poly_solve (df(x), x);
(%o3) %union([x = - 2.872468527640942], [x = - 0.4194144025323134],
[x = 0.3836388367122223], [x = 0.2041221431132173 - 1.789901606296292 %i],
[x = 1.789901606296292 %i + 0.2041221431132173])
Something which is maybe a little surprising is that to_poly_solve has returned a numerical solution instead of exact or symbolic. Tracing allroots shows that to_poly_solve has constructed a quintic equation and punted it to allroots. Since the general quintic doesn't have a solution in terms of radicals, and even in special cases it's probably very messy, maybe it's most useful to have a numerical solution anyway.
Try plot2d(df(x), [x, -3, 1]) to visualize the real roots returned above.
You can try to find a numerical solution. I don't know why solve does not try this. Either you take the ouput of aolveor you do hte folölowing:
(%i1) f(x):=(-5*(x^4+5*x^3-3*x))/(x^2+1);
4 3
(- 5) (x + 5 x + (- 3) x)
(%o1) f(x) := ---------------------------
2
x + 1
(%i2) df(x):=''(diff(f(x), x));
4 3 3 2
10 x (x + 5 x - 3 x) 5 (4 x + 15 x - 3)
(%o2) df(x) := ---------------------- - --------------------
2 2 2
(x + 1) x + 1
Bring it to a common denominator and extract the numerator:
(%i3) xthru(df(x));
4 3 2 3 2
10 x (x + 5 x - 3 x) - 5 (x + 1) (4 x + 15 x - 3)
(%o3) ------------------------------------------------------
2 2
(x + 1)
(%i4) num(%);
4 3 2 3 2
(%o4) 10 x (x + 5 x - 3 x) - 5 (x + 1) (4 x + 15 x - 3)
use allsrootsto find the roots of a polynomial numerically
(%i5) allroots(%);
(%o5) [x = 0.3836388391066617, x = - 0.4194143906217701,
x = 1.789901606296292 %i + 0.2041221431132174,
x = 0.2041221431132174 - 1.789901606296292 %i, x = - 2.872468734711326]
skip the complex solutions
(%i6) sublist(%,lambda([t],imagpart(rhs(t))=0))
;
(%o6) [x = 0.3836388391066617, x = - 0.4194143906217701,
x = - 2.872468734711326]

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

Maxima: How to replace the variables to simplify the equation?

(%i1) r: sqrt(x^2+y^2+z^2);
(r) sqrt(z^2+y^2+x^2)
(%i2) dx: diff(r,x);
(dx) x/sqrt(z^2+y^2+x^2)
I just show a simple code because my code is long and complex.
I want to simplify dx and get the result is x/r not x/sqrt(z^2+y^2+x^2).
However, I can't find the useful command.
Could somebody help me to solve this problem?
In this specific case, you can use subst, although ratsubst is probably useful in a greater number of cases.
(%i1) linel:65;
(%o1) 65
(%i2) r: sqrt(x^2+y^2+z^2);
2 2 2
(%o2) sqrt(z + y + x )
(%i3) diff (r, x);
x
(%o3) ------------------
2 2 2
sqrt(z + y + x )
(%i5) subst (r = 'r, %o3);
x
(%o5) -
r
(%i6) ratsubst ('r, r, %o3);
x
(%o6) -
r
Note that the single quote mark prevents evaluation, so that 'r is the symbol r instead of the value of r (namely sqrt(x^2 + y^2 + z^2)).

linsolve in maxima no work for these equations

I am very novice in maxima. I want to get the solution for W using these equations:
e1: A*W + B*Y = I$
e2: C*W + D*Y = 0$
linsolve ([e1, e2], [W]);
But linsolve just generates [].
The example in the manual works:
(%i1) e1: x + z = y$
(%i2) e2: 2*a*x - y = 2*a^2$
(%i3) e3: y - 2*z = 2$
(%i4) linsolve ([e1, e2, e3], [x, y, z]);
(%o4) [x = a + 1, y = 2 a, z = a - 1]
That means that the equation cannot be solved for the variables that you requested. You have to solve in respect to both variables:
linsolve([e1,e2],[W,Y]);
D I C I
[W = - ---------, Y = ---------]
B C - A D B C - A D
You can solve for W for each of your equations separately. For example:
linsolve ([e1],[W]);
B Y - I
[W = - -------]
A

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.

Resources