# Polynomial has more than one symbolic variable error

10 views (last 30 days)
Tracy Campbell on 9 Oct 2021
Answered: Walter Roberson on 12 Oct 2021
I created a code but recieving an error. Can someone have a look and figure out why and what is the best way to fix it? I'm a novice at Matlab so please be patient & kind.
Thanks
##### 2 CommentsShowHide 1 older comment
Tanmay Das on 12 Oct 2021
Hi, here is the reproduced code to the above image. Please feel free to explore it.
clc
clear all
syms m1 m2 J1 s b k1 k2 k3 r1 xi T real
t=0:0.5:100;
A=[-s^2*m1-s*b-k2, k2, 0; -k2, s^2*m2+k3+k2, -k3; -s^2*J1/r1-s*b/r1, 0, 0];
F=[T;0;T*r1];
U=A\F;
x1=U(1);
x2=U(2);
x3=U(3);
G1=T/xi
G2=x2/xi
gg1 = G1(1);
gg2 = G2(1);
[gg]=subs({gg1, gg2}, {b,k1,k2,k3,m1,m2}, {0.7,100,40,50,20,10});
G1 = gg(1);
G2 = gg(2);
[num1,den1]=numden(G1);
[num2,den2]=numden(G2);
num1=sym2poly(num1);
den1=sym2poly(den1);
num2=sym2poly(num2);
den2=sym2poly(den2);
G1=tf(num1,den1);
G2=tf(num2,den2);
step(G1,t)
figure(2)
step(G2,t)

Tanmay Das on 12 Oct 2021
Hi,
To my understanding, you are passing a polynomial with multiple symbolic variables to sym2poly function which is not allowed. Sym2poly function is basically used to extract vector of all numeric coefficients, including zeros, from symbolic polynomial. Subs function can be used to replace some of the symbolic variables to numeric values like already done with some of the variables in the attached code. The only thing to take care is that the symbolic polynomial passed as an argument to sym2poly function should be of only one symbolic variable.

Walter Roberson on 12 Oct 2021
syms m1 m2 J1 s b k1 k2 k3 r1 xi T real
t=0:0.5:100;
A=[-s^2*m1-s*b-k2, k2, 0; -k2, s^2*m2+k3+k2, -k3; -s^2*J1/r1-s*b/r1, 0, 0];
F=[T;0;T*r1];
U=A\F;
x1=U(1);
x2=U(2);
x3=U(3);
G1=T/xi
G1 =
G2=x2/xi
G2 =
gg1 = G1(1);
gg2 = G2(1);
[gg]=subs({gg1, gg2}, {b,k1,k2,k3,m1,m2}, {0.7,100,40,50,20,10})
gg =
G1 = gg(1)
G1 =
G2 = gg(2)
G2 =
[num1,den1]=numden(G1)
num1 =
T
den1 =
ξ
[num2,den2]=numden(G2)
num2 =
den2 =
You can see that G2 is in terms of T, r1, J1, s, none of which you subs() for.
I suspect that you are trying to extract coeficients of s
[num2, num2s] = coeffs(num2, s, 'all')
num2 =
num2s =
[den2, den2s] = coeffs(den2, s,'all')
den2 =
den2s =
G1=tf(num1,den1)
Error using tf (line 303)
The values of the "Numerator" and "Denominator" properties must be row vectors or cell arrays of row vectors, where each vector is nonempty and containing numeric data. Type "help tf.num" or "help tf.den" for more information.
Which just gets you to the next problem, namely that the coefficients of a transfer function tf() cannot be symbolic.
G2=tf(num2,den2)
step(G1,t)
figure(2)
step(G2,t)
Within the Control System Toolbox, MATLAB has no way at all to deal with symbolic coefficients. The most it has is a way to use tunable parameters. At any one time, a tunable parameter has a distinct value -- it is just that the structure of control systems created with tunable parameters allows the tunable parameters to be detected and manipulated more easily, such as for automatic tuning. But you cannot create a general step() diagram showing the general case, for example: you could only create a step diagram using the current value of the tunable parameter.
I suspect that to proceed you will need to substitute additional specific values like you already do in the subs().
But remember when you do so that you are going to end up with the first system being a scalar constant independent of s -- you can see G1 is independent of s even before any subs()

R2021a

### Community Treasure Hunt

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

Start Hunting!