Plotting multiple outputs with varying inputs in same graph

I am trying to plot for multiple values of b on the same graph without for loop, any way to do this?
Code:
m1 = 10; m2 = 350; kw = 5e5; ks = 1e4; b = 2000; s = tf('s');
transfer = (((kw*b)/(m1*m2))*(s+ks/b))/(s^4 + (b/m1 + b/m2)*s^3 + (ks/m1 + ks/m2 + kw/m1)*s^2 + (kw*b/(m1*m2))*s+ (kw*ks)/(m1*m2));
step(transfer);

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 17 Sep. 2022
Bearbeitet: Walter Roberson am 17 Sep. 2022
It is tricky to do without a loop at some level.
One approach is to use a symbolic approach. The symbolic approach can deal with the fact that you are dividing by vector of transfer functions: tf() objects do not support the ./ operation, but symbolic objects can. But after you have the symbolic expressions you need to convert them back to tf() objects, and the easiest way to do that is to arrayfun(), since the functions that extract coefficients from polynomials do not accept vectors of expressions.
b = 1500:500:2500;
m1 = 10; m2 = 350; kw = 5e5; ks = 1e4;
syms s
transfer = (((kw*b)./(m1*m2)).*(s+ks./b))./(s^4 + (b/m1 + b/m2).*s^3 + (ks/m1 + ks/m2 + kw/m1).*s^2 + (kw*b./(m1*m2))*s + (kw*ks)./(m1*m2))
transfer = 
transfer = simplify(transfer)
transfer = 
transfer = arrayfun(@sym2tf, transfer)
transfer = From input 1 to output: 6.185e17 s + 4.123e18 ------------------------------------------------------------------ 2.886e12 s^4 + 4.453e14 s^3 + 1.473e17 s^2 + 6.185e17 s + 4.123e18 From input 2 to output: 2.749e17 s + 1.374e18 ------------------------------------------------------------------ 9.621e11 s^4 + 1.979e14 s^3 + 4.909e16 s^2 + 2.749e17 s + 1.374e18 From input 3 to output: 3.436e17 s + 1.374e18 ------------------------------------------------------------------ 9.621e11 s^4 + 2.474e14 s^3 + 4.909e16 s^2 + 3.436e17 s + 1.374e18 Continuous-time transfer function.
step(transfer.')
function as_tf = sym2tf(tf_as_sym)
[n, d] = numden(tf_as_sym);
np = sym2poly(n);
dp = sym2poly(d);
as_tf = tf(np, dp);
end

1 Kommentar

Using tf() with arrayfun turned out to be easier than I expected.
b = 1500:500:2500;
m1 = 10; m2 = 350; kw = 5e5; ks = 1e4;
s = tf('s');
transfer = arrayfun(@(b) (((kw*b)/(m1*m2))*(s+ks/b))/(s^4 + (b/m1 + b/m2)*s^3 + (ks/m1 + ks/m2 + kw/m1)*s^2 + (kw*b/(m1*m2))*s + (kw*ks)/(m1*m2)), b)
transfer = From input 1 to output: 2.143e05 s + 1.429e06 ------------------------------------------------------ s^4 + 154.3 s^3 + 5.103e04 s^2 + 2.143e05 s + 1.429e06 From input 2 to output: 2.857e05 s + 1.429e06 ------------------------------------------------------ s^4 + 205.7 s^3 + 5.103e04 s^2 + 2.857e05 s + 1.429e06 From input 3 to output: 3.571e05 s + 1.429e06 ------------------------------------------------------ s^4 + 257.1 s^3 + 5.103e04 s^2 + 3.571e05 s + 1.429e06 Continuous-time transfer function.
step(transfer.')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by