symbolic math - matlab with symbol, how can I shorten numbers? -
syms w a=[141432432 23432*w; 31432*w 3543566] b=[13432*w^2 ; 3424324]
which returns
a = [ 141432432, 23432*w] [ 31432*w, 3543566] b = 13432*w^2 3424324
then
c=a\b c1=c(1) simplify(c1)
returns
c = -(w*(2974823657*w - 5014922498))/(2*(23016082*w^2 - 15661723666641)) (2*(6596791*w^3 - 7567351113687))/(23016082*w^2 - 15661723666641) c1 = -(w*(2974823657*w - 5014922498))/(2*(23016082*w^2 - 15661723666641)) ans = -(w*(2974823657*w - 5014922498))/(2*(23016082*w^2 - 15661723666641))
i want simplify c1
this,
c1 = -(w*(3*e^9*w-5.01*e^9))/......
how can this? when not use syms
variables, numbers looks good. but, if use this, formula dirty.
it may "dirty," that's point of symbolic math – it's accurate full precision of original input. if want result in decimal format should aware less precise unless values can represented (sufficiently short) finite decimal expansion. in matlab's symbolic math toolbox, can use vpa
function convert result variable precision arithmetic:
syms w; c1 = -(w*(2974823657*w - 5014922498))/(2*(23016082*w^2 - 15661723666641)); vpa(c1)
which returns
-(1.0*w*(2974823657.0*w - 5014922498.0))/(46032164.0*w^2 - 31323447333282.0)
this doesn't in case. if want lot less precision, suggested in question, can use digits
or second argument vpa
:
syms w; c1 = -(w*(2974823657*w - 5014922498))/(2*(23016082*w^2 - 15661723666641)); vpa(c1,3) % default value 32
which returns less precise
-(1.0*w*(2.97e9*w - 5.01e9))/(4.6e7*w^2 - 3.13e13)
lastly, can convert symbolic expression floating point function using unfortunately-named matlabfunction
:
syms w; c1 = -(w*(2974823657*w - 5014922498))/(2*(23016082*w^2 - 15661723666641)); c1_fun = matlabfunction(c1)
which returns anonymous function
c1_fun = @(w)-(w.*(w.*2.974823657e9-5.014922498e9))./(w.^2.*4.6032164e7-3.1323447333282e13)
Comments
Post a Comment