Mismatch in vector size within anonymous function
Show older comments
Hi, Im trying to declare a fucntion in matrix form (Jemp) with my input being a vector my issue is that when I try to excute the code I get the following error:
Inner matrix dimensions must agree. Function 'MATLAB Function' (#23.721.737), line 29, column 23: "A*xy_dot(1:10,:)" Launch diagnostic report.
The code is for this is:
b=0.14;%dustance from cog to rear wheels
x_refa=zeros(5,1);%array of references for x to the end of the prediction horizon
y_refa=zeros(5,1);%array of references for y to the end of the prediction horizon
t_ref=zeros(10,1);
x_refa=circshift(x_refa,-1);
y_refa=circshift(y_refa,-1);
x_refa(5)=x_ref;
y_refa(5)=y_ref;
t_ref(1:5)=x_refa;
t_ref(6:10)=y_refa;
Q=ones(5,5);
A=ones(10,5);
H=ones(5,5);
H=tril(H);
A(1:5,:)=H;
A(6:10,:)=H;
A(1:5,1)=x_cur;
A(6:10,1)=y_cur;
T=0.1;%sampling time
%creating error fucntion with prediction
Jemp=@(xy_dot)(t_ref-(A*xy_dot(1:10,:)))'*Q*(t_ref-(A*xy_dot(:,1)));
x0=[x_dot y_dot];
I understand that the problem is that the vector does not have a defined index so the multiplication with matrix A is not working so my question would be how do i define xy_dot in a way that it allows me to define the function.
Edit: I made an edit in the code that solved an initial mistake in the matrix arrangements. However the problem is presisting. Also x_cur is a scalar that i wan to assign to all values in the first column of A.
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!