Clear Filters
Clear Filters

Get constant term of a symbolic function

6 views (last 30 days)
Skye
Skye on 15 Jan 2014
Answered: Skye on 1 Feb 2014
I want to get the constant term of functions, similar to f = 1/(x*(z-1)) - 1/x^2 + 1/(x*z-1) (constant term is -1 regarding x, -1/x - 1/x^2 - 1 regarding z) Usually you could just set x = 0 and leave out Inf, but in this case there would be Inf - Inf, thus matlab displays NaN.
My best idea would be to extract or delete a single term(for example 1/x^2) and check if it's Inf if x = 0, if so then replace 1/x^2 with 0 (using string replace or regexprep or w.e). However i have yet to extract a single term, using splitstring at an operator (+ / -) would also apply inside the denominator.
I also cannot search for specific strings since the functions are generated using partial fractions in a loop and therefore not really predictable.
  2 Comments
Patrik Ek
Patrik Ek on 21 Jan 2014
Edited: Patrik Ek on 21 Jan 2014
Ok I removed my answer since it did not work out. However, there are one way to work this out that should work. I am not really sure of how you do it in matlab. The real problem is that you have a singularity in 0, which makes taylor expansion (which is otherwise a good way to find a constant term) impossible in this case. However, there are an extension to the Taylor Series called Laurent Series. The laurent series uses cauchys intgral formula to make a general polygon expansion as
... + a_-2*x^-2 + a_-1*x^-1 + a_0 + a_1*x + ...,
by using cauchys integral formula, This solution will in all cases give an approximate answer for all functions and for finite length polynomials, the solution will always be exact. THe higher order the higher accuracy. I write this as a comment since the solution is not implemented.
This method did give the correct constant term for your example, when tested in a program outside matlab.
Skye
Skye on 1 Feb 2014
That would indeed work, just takes too much computational effort for a fairly simple problem; I ended up getting my matlab up to date, so i could use the 'children' function, and set terms that give Inf or -Inf for x -> 0 to 0. Thx for your ideas

Sign in to comment.

Accepted Answer

Skye
Skye on 1 Feb 2014
Answer in the comment above

More Answers (0)

Community Treasure Hunt

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

Start Hunting!