Converting syms to double

6 次查看(过去 30 天)
Raj Arora
Raj Arora 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 CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by