Converting syms to double

6 ビュー (過去 30 日間)
Raj Arora
Raj Arora 2021 年 9 月 23 日
回答済み: Star Strider 2021 年 9 月 23 日
Is there a way to use one variable as both syms and double at the same time? I'm running a programme in which one variable takes a double value in the first iteration and then has to give a syms value in the next iteration, but it's throwing an error because I initialised that variable as syms.

回答 (1 件)

Star Strider
Star Strider 2021 年 9 月 23 日
I have no idea what you are actually doing, however converting between symbolic and double is straightforward (if inefficient in some contexts).
Example —
syms t
x = sym(42)
Il = 0;
Iu = 1;
intxt = int(x*t, Il, Iu)
fprintf('The integral of %.1f*t from %.1f to %.1f = %.2f\n', double(x), Il, Iu, double(intxt))
producing:
The integral of 42.0*t from 0.0 to 1.0 = 21.00
The online Run feature is still down for scheduled maintenance, so I cannot run that here.
.

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by