gpt4 book ai didi

matlab - Matlab : ode15i solver raises error about dimensions, I fail to see where

转载 作者:行者123 更新时间:2023-12-03 08:10:22 25 4
gpt4 key购买 nike


% Why?

tstart = 0;
tfinal = 1;
tspan = [tstart tfinal];
options = odeset('Events',@myEventsFcn);

% Initial conditions
y0 = [0,-0.6,0,0,0,0];
yp0 = [0,0,0,0,0,0];
% decic funtion calculates consistent ICs
[y0,yp0] = decic(@StateI,t0,y0,[0 1 0 0 0 0],yp0,[0 0 0 0 0 0]);

% Arrays for plots
tout = tstart;
sout = y0(1:1);
bout = y0(2:2);
zout = y0(3:3);
svout = y0(4:4);
bvout = y0(5:5);
zvout = y0(6:6);

% ode15i solves system of implicit ODEs
[t,y,te,ye,ie] = ode15i(@StateI,tspan,y0,yp0,options);

% system of implicit ODEs defined as StateI function
function res = StateI(t,y,yp)
% Constants
mS = 3*10^(-4); % [kg]
JS = 5*10^(-9); % [kgm]
mB = 4.5*10^(-3); % [kg]
g = 9.81; % [m/s^2]
JB = 7*10^(-7); % [kgm]
lS = 10^(-2); % [m]
lG = 1.5*10^(-2); % [m]
cp = 5.6*10^(-3); % [N/rad]

res = [(mS+mB)*yp(6) + mB*lS*yp(4) + mB*lG*yp(5) + (mS+mB)*g;
mB*lS*yp(6) + (JS+mB*lS^2)*yp(4) + mB*lS*lG*yp(5) - cp*(y(2)-y(1)) + mB*lS*g;
mB*lG*yp(6) + mB*lS*lG*yp(4) + (JB+mB*lG^2)*yp(5) - cp*(y(1)-y(2)) + mB*lG*g;
y(4)-yp(1);
y(5)-yp(2);
y(6)-yp(3)];
end

% my events defined in myEventsFcn
function [value,isterminal,direction] = myEventsFcn(t,y,yp)
% Constants
mS = 3*10^(-4); % [kg]
mB = 4.5*10^(-3); % [kg]
g = 9.81; % [m/s^2]
rS = 3.1*10^(-3); % [m]
lS = 10^(-2); % [m]
r0 = 2.5*10^(-3); % [m]
hS = 2*10^(-2); % [m]
lG = 1.5*10^(-2); % [m]
lB = 2.01*10^(-2); % [m]
hB = 2*10^(-2); % [m]
cp = 5.6*10^(-3); % [N/rad]


Z2 = -(mS+mB)*g-mB*lG*yp(5);
Z1II = (cp*(y(2)+(rS-r0)/hS)-rS*Z2-mB*lS*lG*yp(5)-mB*lS*g)/hS;

value = [y(1)+(rS-r0)/hS, y(1)-(rS-r0)/hS, Z1II, y(2)-(lS+lG-lB- r0)/hB];
isterminal = [1, 1, 1, 1];
direction = [-1, 1, -1, 1];
end

错误信息
Matrix dimensions must agree.

Error in odezero (line 46)
indzc = find((sign(vL) ~= sign(vR)) & (direction .* (vR - vL) >= 0));

Error in ode15i (line 506)
[te,ye,ie,valt,stop] = odezero(@ntrp15i,@events_aux,events_args,valt,...

Error in silly (line 24)
[t,y,te,ye,ie] = ode15i(@StateI,tspan,y0,yp0,options);

所以我之前运行过此代码,没问题,然后此错误开始 pop 。我看不到该错误可能发生的位置。我尝试对 vector y0和yp0进行转置,这并不成功,但是确实给出了另一个错误消息,这似乎很奇怪,因为我认为Matlab的ode求解器可以处理转置的初始条件。

最好的祝福

最佳答案

您的代码在我的MATLAB(2018b)版本上运行得很好。检查您的版本。

关于matlab - Matlab : ode15i solver raises error about dimensions, I fail to see where,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55190693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com