How can I expand a function to a polynomial expression?

I want to expand the equation (1) to (2). I tried as follows, but the result goes back to the equation (1).
clear
clc
syms x k;
assume(-1< x/4 <1);
expand((1-x/2)*symsum((x/4)^k,k,0,inf));
simplify(ans);
pretty(ans)
ans= 2 (x - 2) / ( x - 4 )

 Risposta accettata

John D'Errico
John D'Errico il 12 Nov 2016
Modificato: John D'Errico il 12 Nov 2016
First, even though people think it is nice to write the shorthand in mathematics of
-1< x/4 <1
this is NOT a valid MATLAB condition in general. Yes, YOU know what it is intended to mean. But MATLAB typically does not see things like that.
Luckily, the symbolic toolbox is able to understand what you wrote.
syms x
assume(-1< x/4 <1)
assumptions
ans =
[ -1 < x/4, x/4 < 1]
In normal MATLAB expressions however, what you wrote will fail.
x= -5:5;
-1< x/4 <1
ans =
1 1 0 0 0 0 0 0 0 0 0
Whereas we would have expected a different result.
(-1 < x/4) & (x/4 < 1)
ans =
0 0 1 1 1 1 1 1 1 0 0
So always be careful when you make an assumption of how MATLAB will treat your favorite mathematical shorthand.
Regardless, to solve your problem, simplest is just:
taylor(x/(2*(x/4 - 1)) - 1/(x/4 - 1),'order',10)
ans =
- x^9/262144 - x^8/65536 - x^7/16384 - x^6/4096 - x^5/1024 - x^4/256 - x^3/64 - x^2/16 - x/4 + 1

1 Commento

Deokjae Jeong
Deokjae Jeong il 12 Nov 2016
Modificato: Deokjae Jeong il 12 Nov 2016
Thank you so much ! Your answer exactly and clearly solved my question. I did not know that Matlab does not properly understand "-1< x/4 <1." Thank you.
I learned taylor series at a math class, yet never thought that it could be applied to this problem. It is powerful.

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by