Problem passing a function handle into icare
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I wrote the following code:
A_cen=@(x)[1 1 0 0;0 1 0 0;0 0 x(1) x(2);0 0 0 x(3)];
B_cen=@(x)[1 0;x(4) 0;0 x(5);0 x(6)];
Q1=ones(4,4);
R1=eye(2);
S1=zeros(4,2);
[X_1,F_1,~]=icare(A_cen,B_cen,Q1,R1,S1);
But I receive the following error:
Error using icare (line xx)
Input arguments to function include colon operator. To input the colon character, use ':' instead.
Error in fmincon_test5 (line yy)
[X_1,F_1,~]=icare(A_cen,B_cen,Q1,R1,S1);
I have tried finding an answer online regarding this problem, but it seems the solution is different for different circumstances. Could anybody tell exactly why this error is cropping up here? Thanks a lot beforehand.
댓글 수: 1
dpb
2023년 1월 18일
I don't have the TB but according to the doc icare doesn't accept function handles as inputs; it expects arrays. So evaluate the arrays before passing them.
답변 (1개)
Adam Danz
2023년 1월 19일
편집: Adam Danz
2023년 1월 23일
A_cen and B_cen are functions that require 1 input. Fill in the 2 blanks below. The input to A_cen should have at least 3 elements and the input to B_cen should have at least 6 elements.
A_cen=@(x)[1 1 0 0;0 1 0 0;0 0 x(1) x(2);0 0 0 x(3)];
B_cen=@(x)[1 0;x(4) 0;0 x(5);0 x(6)];
Q1=ones(4,4);
R1=eye(2);
S1=zeros(4,2);
[X_1,F_1,~]=icare(A_cen(___),B_cen(___),Q1,R1,S1)
Perhaps these 2 anonymous functions are designed to receive the same variable that has at least 6 elements.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!