How can I do summation in transfer function?

s = tf('s');
sys_Foster = tf(R_Foster(1)/(1+R_Foster(1)*C_Foster(1)*s)+R_Foster(2)/(1+R_Foster(2)*C_Foster(2)*s)+R_Foster(3)/(1+R_Foster(3)*C_Foster(3)*s));
[N_tf,D_tf] = tfdata(sys_Foster);
If I have a transfer function like the code show
How can I perform sys_Foster not only summation for 3 terms but i terms, where i is size(R_Foster)
I have tried the code below
for i = 1:size(R_Foster)
sys_Foster_i(i) = tf(R_Foster(i)/(1+R_Foster(i)*C_Foster(i)*s))
end
sys_Foster = sum(sys_Foster_i)
but got wrong answer.

 Accepted Answer

One approach
R_Foster = 1:3;
C_Foster = 11:13;
sys_Foster = tf(0)
sys_Foster = 0 Static gain.
for ii = 1:3
sys_Foster = sys_Foster + tf(R_Foster(ii),[R_Foster(ii)*C_Foster(ii) 1])
end
sys_Foster = 1 -------- 11 s + 1 Continuous-time transfer function. sys_Foster = 46 s + 3 ------------------ 264 s^2 + 35 s + 1 Continuous-time transfer function. sys_Foster = 2586 s^2 + 268 s + 6 ------------------------------- 10296 s^3 + 1629 s^2 + 74 s + 1 Continuous-time transfer function.
sys_Foster
sys_Foster = 2586 s^2 + 268 s + 6 ------------------------------- 10296 s^3 + 1629 s^2 + 74 s + 1 Continuous-time transfer function.

6 Comments

Thanks a lot! It really solve my problem.
I have another question like below:
syms s
[N_tf,D_tf] = numden(R_Foster(1)/(1+R_Foster(1)*C_Foster(1)*s)+R_Foster(2)/(1+R_Foster(2)*C_Foster(2)*s)+...
R_Foster(3)/(1+R_Foster(3)*C_Foster(3)*s))
D = sym2poly(N_tf);
N = sym2poly(D_tf);
The same as the original question, How can I transform 3 terms to i terms instead? thank you!
It looks like the assignments to D and N are backwards.
Once you have N and D do you just want to create a tf object? I'm not sure what the desired end result is ...
R_Foster = 1:3;
C_Foster = 11:13;
syms s
[N_tf,D_tf] = numden(R_Foster(1)/(1+R_Foster(1)*C_Foster(1)*s)+R_Foster(2)/(1+R_Foster(2)*C_Foster(2)*s)+...
R_Foster(3)/(1+R_Foster(3)*C_Foster(3)*s));
%D = sym2poly(N_tf);
%N = sym2poly(D_tf);
N = sym2poly(N_tf);
D = sym2poly(D_tf);
tf(N,D)
ans = 2586 s^2 + 268 s + 6 ------------------------------- 10296 s^3 + 1629 s^2 + 74 s + 1 Continuous-time transfer function.
What I really want is that turn the code into
syms s
[N_tf, D_tf]=numden(R_foster(i)/(1+R_foster(i)*C_foster(i)*s))
wher i is 1,2,⋯to size(R_foster)
but I run the code. the result is strange.
the result is not the same as summation each term.
Now I'm very confused as to what the goal actually is. In this answer I showed how to use a loop to add three first order transfer functions together using the Control System Toolbox functions. In this comment I showed how to create the same tf object but adding together the first order transfer functions using the Symbolic Toolbox to get the same result. Maybe you want to use the Symbolic Toolbox but in a loop?
R_Foster = sym(1:3);
C_Foster = sym(11:13);
syms s
H(s) = sym(0);
for ii = 1:numel(R_Foster)
H(s) = H(s) + R_Foster(ii)/(1+R_Foster(ii)*C_Foster(ii)*s);
end
H(s) % this is a symfun object
ans = 
[num,den] = numden(H(s));
H(s) = num/den % still a symfun object
H(s) = 
H(s) = expand(num)/expand(den) % still a symfun object
H(s) = 
If none of this solves the problem, please be more clear about the problem actually is. Do you want a Symbolic result or a Control System Toolbox result? Does the result need to be in a specific format? Etc.
@Paul Thanks a lot! I got the answer I want. You really solve my problem. Really aprreciate.

Sign in to comment.

More Answers (0)

Products

Asked:

on 25 Mar 2022

Commented:

on 27 Mar 2022

Community Treasure Hunt

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

Start Hunting!