Input to num2str must be numeric.

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)) ''])

 Respuesta aceptada

madhan ravi
madhan ravi el 10 de Dic. de 2018
Editada: madhan ravi el 10 de Dic. de 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 comentarios

Abhinay Tadwalkar
Abhinay Tadwalkar el 10 de Dic. de 2018
Thanks, I had got answer last time without using double(). I am confused
Abhinay Tadwalkar
Abhinay Tadwalkar el 10 de Dic. de 2018
For num2str(zetas(1)) there is no double() still it works. How come?
madhan ravi
madhan ravi el 10 de Dic. de 2018
Editada: madhan ravi el 10 de Dic. de 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 el 31 de Mayo de 2022
ok

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 31 de Mayo de 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.

Productos

Versión

R2018b

Etiquetas

Preguntada:

el 10 de Dic. de 2018

Respondida:

el 31 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by