Converting syms to double

조회 수: 7 (최근 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 CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by