symbolic variable multiplication with numerical matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Adelaide
am 14 Apr. 2019
Beantwortet: Steven Lord
am 14 Apr. 2019
Hi,
I need to multiply a smybolic variable with a numerical matrix. My code is:
syms b1 b2 b3 b4
A = b1.*B + b2.*C + b3.*D + b4.*E
B, C, D and E are matrices that contain numbers. b1 to b4 are 1x1 unspecified variables. When I use the code above I get absurd numbers like (5038398039803537*b1)/36028797018963968. The numbers in numerical matrices are between 0 and 1. I am expecting elements of A that look like, for example, 0.4*b1 + 0.7*b2 + 0.1*b3 + 0.2*b4. I don't even understand where that division is coming from. Thanks in advance.
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 14 Apr. 2019
When you perform that multiplication, Symbolic Math Toolbox converts your numbers into rational numbers rather than leaving them as floating-point numbers. Use the vpa function to approximate those rational numbers to a certain number of decimal points, or use subs to substitute numeric values for your symbolic variables then convert to double if necessary.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Conversion Between Symbolic and Numeric finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!