Input to num2str must be numeric.

8 ビュー (過去 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 Center および File ExchangeNumeric Solvers についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by