ODE45 - problem with parameters passed in odefcn
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello,
I encountered a problem with passing extra parameters to ode. I attached the live script file with said issue.
I'll be extremely thankful for any input.
During debbuging I saw that their values inside odefcn nonsensically differ from those that I passed inside.
댓글 수: 0
채택된 답변
Cris LaPierre
2021년 3월 6일
편집: Cris LaPierre
2021년 3월 6일
I found this example helpful: https://www.mathworks.com/help/matlab/ref/ode45.html#bu3uhuk
I think you need to set up your odefun and call to ode45 as follows
odefun = @(t,theta) throwTraj(t,theta,v_tool,robot);
[t, theta] = ode45(odefun, 0:0.01:t_end, theta0);
This means you also need to update the function declaration for throwTraj
function dtheta = throwTraj(t,theta,v_tool,robot)
This will lead to a new error:;
Expected one output from a curly brace or dot indexing expression, but there were 7 results.
Error in forum_example>throwTraj (line 100)
J = [robot.s_hat(1)*p7,...
Error in forum_example (line 59)
odefun = @(t,theta) throwTraj(t,theta,v_tool,robot);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
This is because you calculate J without indexing robot. You have 7 fields, so it calculates a result for each, returning 7. Everywhere else you appear to use indexing. For example
robot(1).u
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!