MATLAB Answers

Error using sym/subs>normalize, Error in sym/subs>mupadsubs, Error in sym/subs

조회 수: 13(최근 30일)
Antonia Juliane Busch
Antonia Juliane Busch 2021년 7월 6일
답변: Tanmay Das 2021년 8월 6일
Hi,
I want to generate a jacobian matrix (12x24) and run into trouble when trying to substitute my vectors.
syms x_s y_s R_s
syms vx_s [1 12]
syms vy_s [1 12]
B = jacobian([sqrt((x_s+vx_s).^2+(y_s+vy_s).^2)-R_s], [vx_s,vy_s]);
B = double(subs(B,{x_s,vx_s,y_s,vy_s,R_s},{x,vx,y,vy,R}));
My vx and vy vectors are 12x1, as well as x and y.
I get the following error:
"Error using sym/subs>normalize (line 231)
"Entries in second argument must be scalar.
"Error in sym/subs>mupadsubs (line 157)
"[X2,Y2,symX,symY] = normalize(X,Y); %#ok
"Error in sym/subs (line 145)
" G = mupadsubs(F,X,Y);
"Error in Ex9Task2 (line 84)
" B = double(subs(B,{x_s,vx_s,y_s,vy_s,R_s},{x,vx,y,vy,R}));
Is there any workaround for this?
Thank you in advance.

답변(1개)

Tanmay Das
Tanmay Das 2021년 8월 6일
subs() can accept an array of variables as its second parameter, and another array the same size as the third parameter, and does a substitution of scalars according to corresponding positions.
subs() can also accept a cell array of variables for the second parameter, and a cell array the same size as the third parameter, and will do a simultaneous substitution of the (possibly array) contents of the cell for the corresponding variable.
But subs() cannot accept a cell array that contains multiple non-scalar arrays for the second parameter. Each cell entry must be scalar.
You can refer to this link for further information. Also, you can go through subs Documentation.
With respect to the question, you can try the following:
B = double(subs(B,[x_s,vx_s,y_s,vy_s,R_s],[x,vx,y,vy,R]));
Instead of:
B = double(subs(B,{x_s,vx_s,y_s,vy_s,R_s},{x,vx,y,vy,R});

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by