Error in ode15i due to dimensions, what does this mean?

时间:2019-03-19 14:58:48

标签: matlab ode

CODE

t0 = 0;
tfinal = 1;
tspan = [t0 tfinal];

optionsII = odeset('Events',@myEventsFcnII);

y0 = [-0.5972 6.2068];
yp0 = 10000*[0.0006 1.0178];


[t,y,te,ye,ie] = ode15i(@(t,y,yp) StateII(t,y,yp),tspan,y0,yp0,optionsII);

function res = StateII(t,y,yp)
% Constants
mB = 4.5*10^(-3); % [kg]
g = 9.81; % [m/s^2]
JB = 7*10^(-7); % [kgm]
rS = 3.1*10^(-3); % [m]
r0 = 2.5*10^(-3); % [m]
hS = 2*10^(-2); % [m]
lG = 1.5*10^(-2); % [m]
cp = 5.6*10^(-3); % [N/rad]

% y = (b,bv)

A = JB+mB*lG^2;
B = cp*(-(rS-r0)/hS)-mB*lG*g; % State II

res = [yp(1)-y(2);
       yp(2)-1/A*(B-cp*y(1))];
end

function [value,isterminal,direction] = myEventsFcnII(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(2);
Z1II = (cp*(y(1)+(rS-r0)/hS)-rS*Z2-mB*lS*lG*yp(2)-mB*lS*g)/hS;

value = [Z1II];
isterminal = [1];
direction = [-1];
end

ERROR MESSAGE

Unable to perform assignment because the size of the left side is 2-by-1 and the size of the right side is 2-by-2.

Error in ode15i (line 241)
meshsol(:,2) = y0 - h*yp0;

Error in sally (line 11)
[t,y,te,ye,ie] = ode15i(@(t,y,yp) StateII(t,y,yp),tspan,y0,yp0,optionsII);

My Matlab version is 2018a. I don't get what the problem is, the dimensions of my vectors y0 and yp0 are the same, so the ode15i shouldnt raise an error about it. ode45 worked before, but I need to solve this system using ode15i because I have an event function dependent on the velocity. How do I solve this? Where is the problem in my code?

1 个答案:

答案 0 :(得分:0)

我正在使用Matlab 2016a,因此我无法确定是否可以使用。如果我使用您的代码,则会收到错误消息。如果我将y0和yp0的定义更改为列向量而不是行向量,则不会出错。这样:

ReadWriteMap