필터 지우기
필터 지우기

can't get the subs command to work after Jacobian

조회 수: 3 (최근 30일)
Kevin Brinneman
Kevin Brinneman 2018년 10월 28일
댓글: Star Strider 2018년 10월 28일
Hello everyone, thank you for taking the time to read my post.
I am trying to change a symbolic variable to a double but when using the command subs() it does nothing in return. First, i tried defining my variables in the following form:
u1=110.9875 u2=20.8102 m1=10;m2=3 r=1;g=9.81 x1=pi/4 x2=2 x3=0 x4=0; syms m1 m2 r g x1 x2 x3 x4 x1_SS x2_SS x3_SS x4_SS u1 u2 u
and run my code to compute the Jacobian. Once the Jacobian was completed, i would do:
subs(m1,m2,r,g,x1,x2,x3,x4,x1_SS,x2_SS,x3_SS,x4_SS,u1,u2,u)
to change the symbolic variables to double. Since none of that worked, this is the code that I am running right now and still can get the script to change syms to double. The code runs and the Jacobian is calculated.
This is my code:
clear all;clc;
syms m1 m2 r g x1 x2 x3 x4 x1_SS x2_SS x3_SS x4_SS u1 u2 u
x=[x1;x2;x3;x4];
u=[u1,u2];
%creating SS representation: x1_SS=x3;
x2_SS=x4;
x3_SS=(-2*m2*x3*x2*x4-g*cos(x1)*(m1*r+m2*x2)+u1)/(m1*r^2+m2*x2^2);
x4_SS=x3^2*x2-g*sin(x1)+((u2))/(m2);
x_SS=[x1_SS;x2_SS;x3_SS;x4_SS];
A_jacobi=jacobian(x_SS,x);
B_jacobi=jacobian(x_SS,u);
subs(u1,110.9875);subs(u2,20.8102);subs(m1,10);subs(m2,3); subs(r,1);subs(g,9.81);subs(x1,pi/4);subs(x2,2);subs(x3,0);subs(x3,0)
A_jacobi
B_jacobi
and this is my output:
A_jacobi = [ 0, 0, 1, 0] [ 0, 0, 0, 1] [ (g*sin(x1)*(m1*r + m2*x2))/(m1*r^2 + m2*x2^2), (2*m2*x2*(g*cos(x1)*(m1*r + m2*x2) - u1 + 2*m2*x2*x3*x4))/(m1*r^2 + m2*x2^2)^2 - (g*m2*cos(x1) + 2*m2*x3*x4)/(m1*r^2 + m2*x2^2), -(2*m2*x2*x4)/(m1*r^2 + m2*x2^2), -(2*m2*x2*x3)/(m1*r^2 + m2*x2^2)] [ -g*cos(x1), x3^2, 2*x2*x3, 0]
B_jacobi =
[ 0, 0] [ 0, 0] [ 1/(m1*r^2 + m2*x2^2), 0] [ 0, 1/m2]
Only syms :/
  댓글 수: 2
madhan ravi
madhan ravi 2018년 10월 28일
편집: madhan ravi 2018년 10월 28일
Format your code properly by selecting the full code and by by pressing the code button {}so that it’s easy to read
Kevin Brinneman
Kevin Brinneman 2018년 10월 28일
Will do, thanks for the advice.

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

채택된 답변

Star Strider
Star Strider 2018년 10월 28일
You have to tell subs the expression in which to do the substitution:
A_jacobi_n = subs(A_jacobi, {u1,u2,m1,m2,r,g,x1,x2,x3}, {110.9875,20.8102,10,3,1,9.81,pi/4,2 0})
B_jacobi_n = subs(B_jacobi, {u1,u2,m1,m2,r,g,x1,x2,x3}, {110.9875,20.8102,10,3,1,9.81,pi/4,2 0})
A_jacobi_n =
[ 0, 0, 1, 0]
[ 0, 0, 0, 1]
[ (981*2^(1/2))/275, (61803*2^(1/2))/48400 - 26637/9680, -(6*x4)/11, 0]
[ -(981*2^(1/2))/200, 0, 0, 0]
B_jacobi_n =
[ 0, 0]
[ 0, 0]
[ 1/22, 0]
[ 0, 1/3]
Note that ‘x4’ remains a symbolic variable. You could also use vpa to get more tractable constants.
  댓글 수: 2
Kevin Brinneman
Kevin Brinneman 2018년 10월 28일
Thank you very much Strider. Works perfectly.
Star Strider
Star Strider 2018년 10월 28일
As always, my pleasure.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by