Getting a shorter, more simple answer as output

2 ビュー (過去 30 日間)
rezheen
rezheen 2025 年 4 月 17 日
編集済み: Walter Roberson 2025 年 4 月 30 日
How can I get a shorter answer, ideally an exact answer but decimal is also fine. This is my code:
syms x y
y=(log(x)/log(4))+(log(x^2)/log(4)); dy=diff(y)
Returns the answer as:
13510798882111488/(6243314768165359*x)
I'd like a simpler answer please such as:
3/(x*log(4)) % Exact answer
or;
2.1640/x % Decimal approximation
Thanks.

採用された回答

Walter Roberson
Walter Roberson 2025 年 4 月 18 日
syms x y
log4 = log(sym(4));
y=(log(x)/log4)+(log(x^2)/log4); dy=diff(y)
dy = 
  2 件のコメント
rezheen
rezheen 2025 年 4 月 30 日
Hi Walter. When I run your code in Matlab (I have R2021a version), I get:
dy=2.1640/x
Which is great, but doesn't get what you get as output but that's probably because I have the older MATLAB version. Thanks for the answer.
Walter Roberson
Walter Roberson 2025 年 4 月 30 日
編集済み: Walter Roberson 2025 年 4 月 30 日
You probably have
sympref('FloatingPointOutput', true)
ans = logical
0
in effect. You want it to be false .

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

その他の回答 (1 件)

rezheen
rezheen 2025 年 4 月 17 日
移動済み: Matt J 2025 年 4 月 17 日
I figured it out with this code:
sympref('FloatingPointOutput',true);
syms x y
y=(log(x)/log(4))+(log(x^2)/log(4)); dy=diff(y)
Output:
dy =
2.1640/x
Thanks in advance.

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by