return the numerator and denimentor

2 ビュー (過去 30 日間)
Fatma Alnabrisi
Fatma Alnabrisi 2019 年 12 月 9 日
コメント済み: Fatma Alnabrisi 2019 年 12 月 9 日
Hi everyone
Is there such a way to return the numerator and the denomenator of a given rational number
for example x = 1/2
I want to get n=1 , d=2

採用された回答

John D'Errico
John D'Errico 2019 年 12 月 9 日
Rat gives rational results for a floating point number, sometimes they are only approximate, of course.
[n,d] = rat(1/2)
n =
1
d =
2
[n,d] = rat(pi)
n =
355
d =
113
  1 件のコメント
Fatma Alnabrisi
Fatma Alnabrisi 2019 年 12 月 9 日
Thank you !

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2019 年 12 月 9 日
編集済み: Matt J 2019 年 12 月 9 日
If x is a symbolic variable, then yes
>> x=sym(1/2);
>> [n,d]=numden(x)
n =
1
d =
2
  1 件のコメント
Fatma Alnabrisi
Fatma Alnabrisi 2019 年 12 月 9 日
Thank you !

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by