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: Extract coefficients of custom variables in symbolic expression
Replies: 1   Last Post: May 23, 2014 7:20 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Christopher Creutzig

Posts: 256
Registered: 2/24/09
Re: Extract coefficients of custom variables in symbolic expression
Posted: May 23, 2014 7:20 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 06.03.14 10:41, François wrote:
> Hello,
>
> I have a symbolic variable vg defined like this
> vg =eg + Rg*ig - (Lg*(eg - vc - Rc*i1 + ig*(Rc + Rg)))/(L2 + Lg)
> all other variables are symbolic as well.
> Now I would like to extract the coefficients (made of symbolic variables Lg,Rg,Rc,L2) of the symbolic variables eg,vc,vi,i1,ig.


> With zero for the absent coefficients! I already tried
> coeffs(di1,[i1 ig vc vi eg])
> but it does not return zero for the missing coefficients, which makes it worthless!


Since you have a multivariate polynomial, where would the ?missing?
coefficients be? (Note that coeffs is not limited to the linear case,
but think about what the output should be for
coeffs(x^5*y^3+y^4+x^4*y^5+x-y,[x,y]) etc. - it would be possible to
return a sparse array, of course, but that does not seem to be what you
are looking for.)

Does the two-output form of coeffs help?

>> [cs, ts] = coeffs(vg,[i1 ig vc vi eg])

cs =

[ (Lg*Rc)/(L2 + Lg), Rg - (Lg*(Rc + Rg))/(L2 + Lg), Lg/(L2 + Lg), 1 -
Lg/(L2 + Lg)]


ts =

[ i1, ig, vc, eg]

I.e., the coefficient for ts(1) is cs(1) etc.

Or, if you're looking only at the linear case, try this:

>> tmp = arrayfun(@(var) diff(vg,var), ...
[i1 ig vc vi eg],'UniformOutput',false);
>> [tmp{:}].'

ans =

(Lg*Rc)/(L2 + Lg)
Rg - (Lg*(Rc + Rg))/(L2 + Lg)
Lg/(L2 + Lg)
0
1 - Lg/(L2 + Lg)


HTH,

Christopher




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.