odeFunction error- Only variables and declared parameters can be symbolic
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
1 Commento
Risposte (2)
Srivardhan Gadila
il 13 Ago 2019
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.
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!