Symbolic int results in deletion of main variable (MATLAB) -
i trying this:
syms x h4 t4 c13; t = 0.6*sin(pi*x); h1x = 0.5*(1 - t); h0 = h1x; h14x = -h4 -t4*(x - 0.5); h24x = h4 + t4*(x - 0.5); symvar(h14x)
which returns
ans = [ h4, t4, x]
then
u13x = (-4*int(h14x, x, 0, x) + c13)/h0 symvar(u13x)
returns
u13x = -(c13 + 4*x*(h4 - t4/2) + 2*t4*x^2)/((3*sin(pi*x))/10 - 1/2) ans = [ c13, h4, t4, x]
and
p12x = -3*int(u13x, x, 0, x) symvar(p12x)
which is
p12x = -3*int(-(c13 + 4*x*(h4 - t4/2) + 2*t4*x^2)/((3*sin(pi*x))/10 - 1/2), x, 0, x) ans = [ c13, h4, t4 ]
as can see u13x
variables [h4, t4, c13, x]
, while integrating p12x
got reduced [h4, t4, c13]
though integral limits variable (in terms of x
). bug? can't seem weird behaviour. there workaround?
here 3 possible workarounds (tested in r2015a).
1. use symbolic function
1 option make input passed sym/symvar
symfun
in terms of x
, use optional second argument specify finite number of variable for:
syms x h4 t4 c13; t = 0.6*sin(pi*x); h1x = 0.5*(1 - t); h0 = h1x; h14x = -h4 -t4*(x - 0.5); u13x = (-4*int(h14x, x, 0, x) + c13)/h0 p12x(x) = -3*int(u13x, x, 0, x) % make symfun, function of x n = realmax; % 4 or greater variables in case symvar(p12x, n) % second argument must finite integer
which returns expected [ x, t4, h4, c13]
. setting second argument large integer value seems work.
2. convert expression string
there 2 versions of symvar
. there symvar
string inputs , sym/symvar
, in symbolic math toolbox, symbolic expressions. 2 forms apparently behave differently in case. so, workaround convert equation int
character string sym/char
before passing symvar
, converting output vector of symbolic variables:
syms x h4 t4 c13; t = 0.6*sin(pi*x); h1x = 0.5*(1 - t); h0 = h1x; h14x = -h4 -t4*(x - 0.5); u13x = (-4*int(h14x, x, 0, x) + c13)/h0 p12x = -3*int(u13x, x, 0, x) sym(symvar(char(p12x))).'
which returns expected [ c13, h4, t4, x]
(note order appears opposite of first workaround above).
3. call mupad function matlab
lastly, can call mupad function indets
finds indeterminates in expression.
syms x h4 t4 c13; t = 0.6*sin(pi*x); h1x = 0.5*(1 - t); h0 = h1x; h14x = -h4 -t4*(x - 0.5); u13x = (-4*int(h14x, x, 0, x) + c13)/h0 p12x = -3*int(u13x, x, 0, x) feval(symengine, 'x->indets(x) minus type::constantidents', p12x)
which returns [ x, c13, h4, t4]
. work if input p12x
class sym
or symfun
. can use:
evalin(symengine, ['indets(hold(' char(p12x) ')) minus type::constantidents'])
the reason sym/symvar
doesn't work in case because based on freeindets
under hood, explicitly ignores free variables in functions int
.
Comments
Post a Comment