Grayson Woods
Grayson Woods

Reputation: 11

Is there a way to prevent MATLAB's simplify()/numden() function from cancelling equal numerator/denominator terms?

I am trying to find the denominator of a given fraction G, but I cannot find a way to use MATLAB's built-in functions without oversimplifying the fraction, and losing important information.

I've tried using MATLAB's built-in commands "numden", "simplify", and "simplifyFraction" but they keep cancelling equal terms from the numerator and denominator. This is normally okay, but for my application, I need to know all values in the denominator which might cause a hole/instability in the function, G.

I've tried looking into the additional constraints within those functions like "IgnoreAnalyticConstraints", but they don't seem to fix the issue. I've simplified my code to isolate my problem below with my current attempts:

syms 's'
G = 2/(s - 1) + 1/(s + 1) - 4/((s - 1)*(s + 1));
[n,d]=numden(G)
G_simp=simplify(G)
G_simpC=simplify(G,'IgnoreAnalyticConstraints',false)
G_simpF=simplifyFraction(G)

Output:
n = 3
d = s + 1
G_simp = 3/(s + 1)
G_simpC = 3/(s + 1)
G_simpF = 3/(s + 1)

Here is an example fraction input: G = 2/(s - 1) + 1/(s + 1) - 4/((s - 1)*(s + 1))

which simplifies to: G = 3*(s - 1)/((s - 1)*(s + 1)). <-desired result

I am trying to keep the fraction in this simplified form, but the built-in commands will cancel the (s-1) terms resulting in: G = 3/(s + 1). <-actual result

Upvotes: 1

Views: 488

Answers (1)

AVK
AVK

Reputation: 2149

You can use the Control System Toolbox:

s= tf([1 0],1);
G = 2/(s - 1) + 1/(s + 1) - 4/((s - 1)*(s + 1))
zpk(G)

The code s= tf([1 0],1); creates a variable s. It contains a Transfer Function object that represents the transfer function f(s)=s. The line

G = 2/(s - 1) + 1/(s + 1) - 4/((s - 1)*(s + 1))

creates a Transfer Function object that contains the corresponding transfer function. And zpk(G) converts this function to the zero/pole/gain form.

The result of the code above is

G =

3 s^3 - 3 s^2 - 3 s + 3   
-----------------------
  s^4 - 2 s^2 + 1   

Continuous-time transfer function.

ans =

3 (s+1) (s-1)^2   
---------------   
(s+1)^2 (s-1)^2   

Continuous-time zero/pole/gain model.

Upvotes: 1

Related Questions