Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Extracting Coefficients from differential equations

Subject: Extracting Coefficients from differential equations

From: Mirage

Date: 18 Oct, 2012 14:40:09

Message: 1 of 6

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. To clarify things, I'm not trying to solve the equation, I just want to extract the coefficients.

Many Thanks

Subject: Extracting Coefficients from differential equations

From: Ryan

Date: 29 Oct, 2012 18:46:08

Message: 2 of 6

str = '12hjb42&34ni3&(*&'; %# Your sample string
alphaStr = str(isstrprop(str,'alpha')); %# Get the alphabetic characters
digitStr = str(isstrprop(str,'digit')); %# Get the numeric characters
otherStr = str(~isstrprop(str,'alphanum')); %# Get everything that isn't an
                                             %# alphanumeric character


"Mirage " <miragel@uvic.ca> wrote in message <k5p4c8$1cv$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. To clarify things, I'm not trying to solve the equation, I just want to extract the coefficients.
>
> Many Thanks

Subject: Extracting Coefficients from differential equations

From: Ryan

Date: 29 Oct, 2012 18:49:08

Message: 3 of 6

Here's one more for you to try:
str = '24.42x3 - 0.87x2 + x + 489'
idx = regexp(str,'\d+')
nums = regexp(str,'\d+','match')
%%To get the numbers out, as opposed to strings, use:
str2num(nums{1})

Where is that one coming from????

"Mirage " <miragel@uvic.ca> wrote in message <k5p4c8$1cv$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. To clarify things, I'm not trying to solve the equation, I just want to extract the coefficients.
>
> Many Thanks

Subject: Extracting Coefficients from differential equations

From: Steven_Lord

Date: 30 Oct, 2012 14:24:00

Message: 4 of 6



"Ryan " <ryanshuell@gmail.com> wrote in message
news:k6mj34$isd$1@newscl01ah.mathworks.com...
> Here's one more for you to try:
> str = '24.42x3 - 0.87x2 + x + 489'
> idx = regexp(str,'\d+')
> nums = regexp(str,'\d+','match')
> %%To get the numbers out, as opposed to strings, use:
> str2num(nums{1})
>
> Where is that one coming from????

The character '.' is not a digit and so doesn't match \d. Try:

>> idx = regexp(str,'[\d\.]+')
>> nums = regexp(str,'[\d\.]+', 'match')

But note that this is not perfect; x's coefficient of 1 is implicit, so it
is not present to be detected by REGEXP. You could probably try to tokenize
based on + or - and then try to figure out the form of each term
independently, but even that doesn't necessarily work.

>> format short
>> 1234567890

ans =

   1.2346e+09

To the OP, what SPECIFICALLY are you planning to use this information to do?
There may be an alternate way to achieve your ultimate goal that doesn't
involve parsing a string whose format could be extremely variable.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Extracting Coefficients from differential equations

From: Mirage

Date: 30 Oct, 2012 18:57:08

Message: 5 of 6

> To the OP, what SPECIFICALLY are you planning to use this information to do?
> There may be an alternate way to achieve your ultimate goal that doesn't
> involve parsing a string whose format could be extremely variable.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Hi Steve,

Thanks for the reply. I've been using activex to automate excel and I had to create graphs and extract the trendlines. At the time, the only way I knew how was by extracting the string value of the trendline from the text using datalabel.text and then using regexp to extract the coefficients... I actually was able to get an algorithm going that covered the various coefficient outcomes but unfortunately I ended up having other trouble with using the datalabel.text function so I started using LinEst and Polyfit to get the y and r2 equations. Unfortunately I seem to be running into a bit of a problem with polyfit for order 2 and 3 equations at times.

Subject: Extracting Coefficients from differential equations

From: Christopher Creutzig

Date: 9 Jan, 2013 12:46:52

Message: 6 of 6

On 18.10.12 16:40, Mirage wrote:

> 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

Where is that a differential equation?

If you are looking for something handling differential equations, such
as y''(t) = y'(t)*t^2 - (y(t)+1)^2, check out odeToVectorField from the
Symbolic Math Toolbox.


Christopher

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us