subs command is not working on differentiation in MATLAB

조회 수: 3 (최근 30일)
SOUVIK BASAK
SOUVIK BASAK 2022년 6월 4일
답변: Walter Roberson 2022년 6월 5일
I have defined theta1 and theta2 as my random functions of time. I have defined vec_a1 and vec_v1 by differentiaing them. Afterwards when I am defining theta1 and theta2 and trying to evaluate vec_a1 and vec_v1 it is not converting to numerical values.
g = -9.81;
I1=1;I2=1.5;l1=2;l2=1;rho1=1.1;rho2=0.4;
syms theta1(t) theta2(t)
vec_rho1 = [rho1*cos(theta1), rho1*sin(theta1)];
vec_l1 = [l1*cos(theta1), l1*sin(theta1)];
vec_rho2 = vec_l1 + [rho2*cos(theta2), rho2*sin(theta2)];
vec_l2 = vec_l1 + [l2*cos(theta2), l2*sin(theta2)];
vec_v1 = diff(vec_rho1, t);
vec_a1 = diff(vec_v1, t);
vec_v2 = diff(vec_rho2, t);
vec_a2 = diff(vec_v2, t);
theta1=0.02*t;
theta2=0.3*t;
xx=1
xx = 1
vec_a1=subs(vec_a1)
vec_a1(t) = 
x=vec_a1(xx);
x=double(x)
Error using symengine
Unable to convert expression containing remaining symbolic function calls into double array. Argument must be expression that evaluates to number.

Error in sym/double (line 868)
Xstr = mupadmex('symobj::double', S.s, 0);
  댓글 수: 3
Walter Roberson
Walter Roberson 2022년 6월 5일
subs(expression) is well defined. It means that matlab should look through all of the symvar() and replace them by their values in scope.
SOUVIK BASAK
SOUVIK BASAK 2022년 6월 5일
편집: SOUVIK BASAK 2022년 6월 5일
@Walter Roberson and @Torsten I have updated the question according to your comments. The error I am facing is that subs is replacing theta 1 and theta2 with their respective functions, but could replace the derivative part. As you can see in vec_a1 instead of replacing t it is getting replaced with t(t). Kindly guide me
Thanks,
Souvik

댓글을 달려면 로그인하십시오.

답변 (2개)

Dyuman Joshi
Dyuman Joshi 2022년 6월 5일
g = -9.81;
I1=1;I2=1.5;l1=2;l2=1;rho1=1.1;rho2=0.4;
syms theta1(t) theta2(t)
theta1=0.02*t;
theta2=0.3*t;
vec_rho1 = [rho1*cos(theta1), rho1*sin(theta1)];
vec_l1 = [l1*cos(theta1), l1*sin(theta1)];
vec_rho2 = vec_l1 + [rho2*cos(theta2), rho2*sin(theta2)];
vec_l2 = vec_l1 + [l2*cos(theta2), l2*sin(theta2)];
vec_v1 = diff(vec_rho1, t);
vec_a1 = diff(vec_v1, t);
vec_v2 = diff(vec_rho2, t);
vec_a2 = diff(vec_v2, t);
xx=1;
x=subs(vec_a1,t,xx)
x = 
double(x)
ans = 1×2
1.0e-03 * -0.4399 -0.0088

Walter Roberson
Walter Roberson 2022년 6월 5일
theta1(t)=0.02*t;
theta2(t)=0.3*t;
That is, you had replaced the function theta1 (a function of t) with the symbolic variable theta1 that was not a function.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by