Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Extracting Coefficients from differential equations
Replies: 2   Last Post: Oct 29, 2012 3:03 PM

 Messages: [ Previous | Next ]
 Richard Crozier Posts: 117 Registered: 3/19/09
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

polystr = 'y = 24.42x3 - 0.87x2 + x + 489'

matchstr = '(?<=[\s+\-])x'

newpolystr = regexprep(polystr, matchstr, '1')

matchstr = '(?<!x)([-+]?[0-9]*\.?[0-9]+)((?=x)|(?=\b))'

[S,E,TE,M] = regexp(newpolystr, matchstr)

for i = 1:numel(M)

coeff(i) = str2double(M{i});

end

coeff

Date Subject Author
10/18/12 Mirage
10/18/12 Richard Crozier
10/29/12 ryanshuell@gmail.com