How to display pi symbol in the output?

์กฐํšŒ ์ˆ˜: 212 (์ตœ๊ทผ 30์ผ)
GULZAR
GULZAR 2023๋…„ 8์›” 24์ผ
๋Œ“๊ธ€: Hiro Yoshino 2023๋…„ 8์›” 24์ผ
how to display pi symbol instead of numerical value in the out of the given code
clc; clear all; close all;
nA=3.3;nB=2.25;
% nB=3.3;nA=2.25;
S=sign(1-(nA^2/nB^2));
x=-1i*log(S);
if x>0
disp('Zak Phase of 0th band = ')
disp(pi)
else
disp('Zak Phase of 0th band = ')
disp('0')
end
Zak Phase of 0th band =
3.1416
  ๋Œ“๊ธ€ ์ˆ˜: 1
Fangjun Jiang
Fangjun Jiang 2023๋…„ 8์›” 24์ผ
sprintf('\x3c0')
ans = 'ฯ€'
double('ฯ€')
ans = 960

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Dyuman Joshi
Dyuman Joshi 2023๋…„ 8์›” 24์ผ
You can either use the symbolic math toolbox or print the symbol via the unicode value -
nA=3.3;nB=2.25;
% nB=3.3;nA=2.25;
S=sign(1-(nA^2/nB^2));
x=-1i*log(S);
if x>0
disp('Zak Phase of 0th band = ')
%pi as a symbolic number
disp(sym(pi))
%print the symbol via unicode value
fprintf('%c', 960)
else
disp('Zak Phase of 0th band = ')
disp('0')
end
Zak Phase of 0th band =
ฯ€
ฯ€

์ถ”๊ฐ€ ๋‹ต๋ณ€ (2๊ฐœ)

Nathan Hardenberg
Nathan Hardenberg 2023๋…„ 8์›” 24์ผ
ํŽธ์ง‘: Nathan Hardenberg 2023๋…„ 8์›” 24์ผ
You can display pi as a sybolic
disp(sym(pi))
ฯ€
Or you can use a ฯ€-character (๐œ‹ or ฯ€).
disp("๐œ‹")
๐œ‹
disp("ฯ€")
ฯ€

Hiro Yoshino
Hiro Yoshino 2023๋…„ 8์›” 24์ผ
How about this?
S = sprintf('Zak Phase of 0th band = %c',960);
disp(S);
Zak Phase of 0th band = ฯ€
  ๋Œ“๊ธ€ ์ˆ˜: 1
Hiro Yoshino
Hiro Yoshino 2023๋…„ 8์›” 24์ผ
Please refer to the list of Unicode for your help:List of Unicode characters

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Symbolic Math Toolbox์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

์ œํ’ˆ


๋ฆด๋ฆฌ์Šค

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by