Input to num2str must be numeric.

8 vues (au cours des 30 derniers jours)
Abhinay Tadwalkar
Abhinay Tadwalkar le 10 Déc 2018
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)) ''])

Réponse acceptée

madhan ravi
madhan ravi le 10 Déc 2018
Modifié(e) : madhan ravi le 10 Déc 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 commentaires
madhan ravi
madhan ravi le 10 Déc 2018
Modifié(e) : madhan ravi le 10 Déc 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
Salvatore Veneruso
Salvatore Veneruso le 31 Mai 2022
ok

Connectez-vous pour commenter.

Plus de réponses (1)

Steven Lord
Steven Lord le 31 Mai 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
Name Size Bytes Class Attributes H 1x5 40 double zetas 1x5 8 sym
fprintf("H: %s.\n", string(H))
H: 10. H: 5. H: 2.66. H: 1. H: 0.5.
fprintf("zetas: %s.\n", string(zetas))
zetas: 1/20. zetas: 1/10. zetas: 25/133. zetas: 1/2. zetas: 1.

Tags

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by