odeFunction error- Only variables and declared parameters can be symbolic

조회 수: 5 (최근 30일)
AdarG
AdarG 2019년 8월 7일
댓글: AdarG 2019년 8월 17일
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에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by