Converting syms to double

6 views (last 30 days)
Raj Arora
Raj Arora on 23 Sep 2021
Answered: Star Strider on 23 Sep 2021
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.

Answers (1)

Star Strider
Star Strider on 23 Sep 2021
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.
.

Community Treasure Hunt

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

Start Hunting!