Input to num2str must be numeric.

조회 수: 9 (최근 30일)
Abhinay Tadwalkar
Abhinay Tadwalkar 2018년 12월 10일
답변: Steven Lord 2022년 5월 31일
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)) ''])

채택된 답변

madhan ravi
madhan ravi 2018년 12월 10일
편집: madhan ravi 2018년 12월 10일
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
madhan ravi
madhan ravi 2018년 12월 10일
편집: madhan ravi 2018년 12월 10일
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 2022년 5월 31일
ok

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2022년 5월 31일
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.

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by