Input to num2str must be numeric.
8 views (last 30 days)
Show older comments
Abhinay Tadwalkar
on 10 Dec 2018
Answered: Steven Lord
on 31 May 2022
clc;
disp('a')
syms H zeta
omega = 1;
solve(H == 1/sqrt((1-omega^2)^2 + (2*zeta*omega)^2),zeta);
H = [10 5 2.66 1 0.5];
for i=1:5
zetas(i) = 1/(2*H(i));
end
disp([' Damping Factor for system 1 = ' num2str(zetas(1)) ''])
disp([' Damping Factor for system 2 = ' num2str(zetas(2)) ''])
disp([' Damping Factor for system 3 = ' num2str(zetas(3)) ''])
disp([' Damping Factor for system 4 = ' num2str(zetas(4)) ''])
disp([' Damping Factor for system 5 = ' num2str(zetas(5)) ''])
disp('----------------x---------------')
disp('b')
clear omega
syms omega
for i=1:3
omegas = solve(1 == 1/sqrt((1-omega^2)^2 + (2*zetas(i)*omega)^2));
omega_star(i) = max(omegas);
end
disp([' Omeaga* for system 1 = ' num2str(omega_star(1)) ''])
disp([' Omeaga* for system 2 = ' num2str(omega_star(2)) ''])
disp([' Omeaga* for system 3 = ' num2str(omega_star(3)) ''])
Getiing error for num2str(omega_star).... Input to num2str must be numeric.
It works for the disp([' Damping Factor for system 1 = ' num2str(zetas(1)) ''])
0 Comments
Accepted Answer
madhan ravi
on 10 Dec 2018
Edited: madhan ravi
on 10 Dec 2018
Use double() because omega_star is of symbolic class , ofcourse it can be acheived using fprintf() or sprintf()
num2str(double(omega_star(1))) % do the same for the rest
4 Comments
madhan ravi
on 10 Dec 2018
Edited: madhan ravi
on 10 Dec 2018
because it's of type double by nature , by default solve() returns the answer with symbolic class not of type double , you can always check the class of the variable using whos
whos zetas % it will return type double
whos omega_star %it will return type sym
More Answers (1)
Steven Lord
on 31 May 2022
I would consider using string in this case, as that can convert either numeric or symbolic expressions to text.
H = [10 5 2.66 1 0.5];
zetas = sym(1)./(2*H);
whos H zetas
fprintf("H: %s.\n", string(H))
fprintf("zetas: %s.\n", string(zetas))
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!