
Re: Extracting Coefficients from differential equations
Posted:
Oct 18, 2012 3:55 PM


"Mirage " <miragel@uvic.ca> wrote in message <k5p4ad$11d$1@newscl01ah.mathworks.com>... > Hi, > > I'm would like to know if there is a matlab function that will extract the coefficients from a differential equation. > > E.g. > y = 24.42x3  0.87x2 + x + 489 > > I want to extract the numbers 24.42, 0.87, 1, and 489. > > Thanks
How about?
polystr = 'y = 24.42x3  0.87x2 + x + 489'
matchstr = '(?<=[\s+\])x'
newpolystr = regexprep(polystr, matchstr, '1')
matchstr = '(?<!x)([+]?[09]*\.?[09]+)((?=x)(?=\b))'
[S,E,TE,M] = regexp(newpolystr, matchstr)
for i = 1:numel(M)
coeff(i) = str2double(M{i});
end
coeff

