Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Richard Crozier

Posts: 111
Registered: 3/19/09
Re: Extracting Coefficients from differential equations
Posted: Oct 18, 2012 3:55 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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)([-+]?[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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.