Casteurr
Casteurr

Reputation: 956

MATLAB Common denominator

I have this MATLAB function which receives the following input:

A=[0 1; 0 -1];
B=[0; 1]
C=[-1 1];

Here is the code:

function [ T ] = transferMAtrix( A, B, C )
    s=sym('s');
    [n n] = size(A);
    sI=s*sym(eye(n));
    T=sym(C)*inv(sI-sym(A))*sym(B);

end

And transferMAtrix(A, B, C) returns the following output:

1/(s + 1) - 1/(s*(s + 1))

My questions is: is there a method to make those fractions have the same denominator so that the output would be:

(s-1)/(s*(s+1))

?

Upvotes: 2

Views: 1620

Answers (1)

jkt
jkt

Reputation: 2578

>> syms s
>> T=1/(s + 1) - 1/(s*(s + 1))

T =

1/(s + 1) - 1/(s*(s + 1))

>> [n,d]=numden(T)

n =

s - 1


d =

s^2 + s

>> T=n/d

T =

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

Upvotes: 1

Related Questions