odeFunction error- Only variables and declared parameters can be symbolic

2 次查看(过去 30 天)
Hi,
I have the following code (deriving the Lagrangian equations). I get an error when I call odeFunction:
Error using mupadengine/feval (line 187)
Found symbolic object 'k' in DAEs. Only variables and declared parameters can be symbolic.
Error in sym/odeFunction (line 118)
A = feval(symengine, 'daetools::odeFunction', expr, vars, params{:});
I also get an error (different one) when using matlabFunction
What's wrong? How can I convert to numeric function handle to solve with ode solvers?
Thanks, Adar
my code:
clc
clearvars
syms y theta(t) thetad(t) r(t) rd(t) rd_f thetad_f r0(theta) k(theta) m g cr ctheta
y=symfun(r(t)*cos(theta(t)),t);
xdot=rd*sin(theta)+r*cos(theta)*thetad-0.5*r0(theta)*thetad;
ydot=rd*cos(theta)-r*thetad*sin(theta);
T=m/2*(xdot^2+ydot^2);
V=k(theta(t))/2*(r0(theta(t))-r(t))^2+m*g*cos(theta(t))*r(t);
L=T-V;
% derivatiation Lagrangian to q and qdot
dLdq=[functionalDerivative(L,r);functionalDerivative(L,theta)];
dLdqd=[functionalDerivative(L,rd); functionalDerivative(L,thetad)];
% defining sym functions (derivatives)
rd_f=diff(r(t),t);
thetad_f=diff(theta(t),t);
losses=[m*cr*rd_f; m*r^2*ctheta*thetad_f];
% subsituting from symbolic vars [rd,thetad] to sym functions
dLdq_f=subs(dLdq,[thetad,rd],[thetad_f,rd_f]);
dLdqd_f=subs(dLdqd,[thetad,rd],[thetad_f,rd_f]);
dLdqdd_f=diff(dLdqd_f,t);
% fromulation the ODE equations
eq=dLdqdd_f-dLdq_f+losses;
[eqs,vars] = reduceDifferentialOrder(eq,[r,theta]);
[M,F] = massMatrixForm(eqs,vars);
% transfering to ode handels
f=M\F;
odefun = odeFunction(f,vars,r0, k, m, g ,cr, ctheta); % I get an error
ff=matlabFunction(F); % I get an error here too

回答(2 个)

AdarG
AdarG 2019-8-13
Hi, yes they are known

Srivardhan Gadila
Srivardhan Gadila 2019-8-13
In that case declare the functions r0, k using function handle & remove their symbolic declarations in the line 3 (syms r0(theta) k(theta)) and also remove the r0, k from the odeFunction's arguments. Then try running the code.
  1 个评论
AdarG
AdarG 2019-8-17
Thanks, but what if I don't know in advance the functions of r0(theta), k(theta)?
Can I get a general expression to the derivatives, like r0'(theat) and k'(theta)?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by