Input variable value to matrix

10 visualizaciones (últimos 30 días)
Ivan Dwi Putra
Ivan Dwi Putra el 10 de Jun. de 2020
Comentada: Ivan Dwi Putra el 10 de Jun. de 2020
This is my code
clear; close; clc;
syms a1_head a2_head b hstar
%Parameter Massa
m1 = 8095; % massa train set 1 dalam kg
m2 = 8500; % massa train set 2 dalam kg
g = 10;
c_0_1 = 0.01176;
c_1_1 = 0.00077616;
c_2_1 = 4.48 ;
c_0_2 = 0.01176 ;
c_1_2 = 0.00077616;
c_2_2 = 4.48;
v_0 = 300;
hstar = 120;
a_1 = -1./m1.*(c_1_1 + 2.*c_2_1.*v_0);
a_2 = -1./m2.*(c_1_2 + 2.*c_2_2.*v_0);
a_1_head = 1-(a_1.*hstar);
a_2_head = 1-(a_2.*hstar);
b = 1;
% Model data
A = sym(zeros(4,4));
A(1,2) = a_1_head;
A(3,2) = (a_2_head) - 1; A(3,4) = a_2_head;
display(A);
B = sym(zeros(4,2));
B(1,1) = -b*hstar;
B(2,1) = b;
B(3,2) = -b*hstar ;
B(4,1) = -b; B(4,2) = b;
display(B);
% % Q and R matrices for ARE
% Q = sym(zeros(4,4)); Q(1,:) = [1578 1200 1300 1400]; Q(2,:) = [2985 1578 2985 2985]; Q(3,:) = [2000 2100 1578 2300]; Q(4,:) = [1310 1330 1350 1578]; display(Q);
% R = sym(zeros(2,2)); R(1,:) = [165765 995000]; R(2,:) = [995000 150965]; display(R);
% Q and R matrices for ARE
Q = sym(zeros(4,4)); Q(1,:) = [10 1 1 1]; Q(2,:) = [1 10 1 1]; Q(3,:) = [1 1 10 1]; Q(4,:) = [1 1 1 10]; display(Q);
R = sym(zeros(2,2)); R(1,:) = [1 2]; R(2,:) = [2 3]; display(R);
% % % S matrix Value
% Element Matriks S Value
s1 = 1;
s2 = 2;
s3 = 3;
s4 = 4;
% Matrix S to find
svar = sym('s',[1 16]);
S = [svar(1:4); svar(5:8); svar(9:12); svar(13:16)];
S(2,1) = svar(2);
S(2,2) = svar(1);
S(2,4) = svar(2);
S(3,1) = svar(3);
S(3,2) = svar(7);
S(3,3) = svar(1);
S(4,1) = svar(4);
S(4,2) = svar(2);
S(4,3) = svar(12);
S(4,4) = svar(1);
display(S);
% LHS of ARE: A'*S + S*A' - S*B*Rinv*B'*S
left_ARE = transpose(A)*S + S*A - S*B*inv(R)*transpose(B)*S;
display(left_ARE);
% RHS of ARE: -Q
right_ARE = -Q;
display(right_ARE);
s1 = 1;
s2 = 5;
s3 = 10;
i want to input variabel value
s1 = 1;
s2 = 5;
s3 = 10;
to the left_ARE matrix but the problem when i write the s1-s3 value, the variable in left_ARE still not change
my left_ARE matrix
left_ARE =
[ s4*(600*s1 - 5*s2 - 360*s3 + 8*s4) - s2*(360*s1 - 3*s2 - 240*s3 + 5*s4) - s3*(28800*s1 - 240*s2 - 14400*s3 + 360*s4) + s1*(43200*s1 - 360*s2 - 28800*s3 + 600*s4), (2874340168023969*s1)/70368744177664 + (2670370432474805*s3)/70368744177664 - s1*(360*s1 - 3*s2 - 240*s3 + 5*s4) + s2*(600*s1 - 5*s2 - 360*s3 + 8*s4) - s7*(28800*s1 - 240*s2 - 14400*s3 + 360*s4) + s2*(43200*s1 - 360*s2 - 28800*s3 + 600*s4), s12*(600*s1 - 5*s2 - 360*s3 + 8*s4) - s7*(360*s1 - 3*s2 - 240*s3 + 5*s4) - s1*(28800*s1 - 240*s2 - 14400*s3 + 360*s4) + s3*(43200*s1 - 360*s2 - 28800*s3 + 600*s4), (2740739176652469*s3)/70368744177664 - s2*(360*s1 - 3*s2 - 240*s3 + 5*s4) + s1*(600*s1 - 5*s2 - 360*s3 + 8*s4) - s12*(28800*s1 - 240*s2 - 14400*s3 + 360*s4) + s4*(43200*s1 - 360*s2 - 28800*s3 + 600*s4)]
[ (2874340168023969*s1)/70368744177664 + (2670370432474805*s3)/70368744177664 + s2*(3*s1 - 365*s2 + 240*s7) - s4*(5*s1 - 608*s2 + 360*s7) + s3*(240*s1 - 29160*s2 + 14400*s7) - s1*(360*s1 - 43800*s2 + 28800*s7), (2874340168023969*s2)/35184372088832 + (2670370432474805*s7)/35184372088832 + s1*(3*s1 - 365*s2 + 240*s7) - s2*(5*s1 - 608*s2 + 360*s7) + s7*(240*s1 - 29160*s2 + 14400*s7) - s2*(360*s1 - 43800*s2 + 28800*s7), (2670370432474805*s1)/70368744177664 + (2874340168023969*s3)/70368744177664 + s7*(3*s1 - 365*s2 + 240*s7) - s12*(5*s1 - 608*s2 + 360*s7) + s1*(240*s1 - 29160*s2 + 14400*s7) - s3*(360*s1 - 43800*s2 + 28800*s7), (2874340168023969*s4)/70368744177664 + (2740739176652469*s7)/70368744177664 + (2670370432474805*s12)/70368744177664 + s2*(3*s1 - 365*s2 + 240*s7) - s1*(5*s1 - 608*s2 + 360*s7) + s12*(240*s1 - 29160*s2 + 14400*s7) - s4*(360*s1 - 43800*s2 + 28800*s7)]
[ s2*(240*s1 - 360*s3 + 3*s7 - 5*s12) - s4*(360*s1 - 600*s3 + 5*s7 - 8*s12) + s3*(14400*s1 - 28800*s3 + 240*s7 - 360*s12) - s1*(28800*s1 - 43200*s3 + 360*s7 - 600*s12), (2670370432474805*s1)/70368744177664 + (2874340168023969*s3)/70368744177664 + s1*(240*s1 - 360*s3 + 3*s7 - 5*s12) - s2*(360*s1 - 600*s3 + 5*s7 - 8*s12) + s7*(14400*s1 - 28800*s3 + 240*s7 - 360*s12) - s2*(28800*s1 - 43200*s3 + 360*s7 - 600*s12), s7*(240*s1 - 360*s3 + 3*s7 - 5*s12) - s12*(360*s1 - 600*s3 + 5*s7 - 8*s12) + s1*(14400*s1 - 28800*s3 + 240*s7 - 360*s12) - s3*(28800*s1 - 43200*s3 + 360*s7 - 600*s12), (2740739176652469*s1)/70368744177664 + s2*(240*s1 - 360*s3 + 3*s7 - 5*s12) - s1*(360*s1 - 600*s3 + 5*s7 - 8*s12) + s12*(14400*s1 - 28800*s3 + 240*s7 - 360*s12) - s4*(28800*s1 - 43200*s3 + 360*s7 - 600*s12)]
[ (2740739176652469*s3)/70368744177664 - s2*(5*s1 - 3*s2 + 360*s4 - 240*s12) + s4*(8*s1 - 5*s2 + 600*s4 - 360*s12) - s3*(360*s1 - 240*s2 + 28800*s4 - 14400*s12) + s1*(600*s1 - 360*s2 + 43200*s4 - 28800*s12), (2874340168023969*s4)/70368744177664 + (2740739176652469*s7)/70368744177664 + (2670370432474805*s12)/70368744177664 - s1*(5*s1 - 3*s2 + 360*s4 - 240*s12) + s2*(8*s1 - 5*s2 + 600*s4 - 360*s12) - s7*(360*s1 - 240*s2 + 28800*s4 - 14400*s12) + s2*(600*s1 - 360*s2 + 43200*s4 - 28800*s12), (2740739176652469*s1)/70368744177664 - s7*(5*s1 - 3*s2 + 360*s4 - 240*s12) + s12*(8*s1 - 5*s2 + 600*s4 - 360*s12) - s1*(360*s1 - 240*s2 + 28800*s4 - 14400*s12) + s3*(600*s1 - 360*s2 + 43200*s4 - 28800*s12), (2740739176652469*s12)/35184372088832 - s2*(5*s1 - 3*s2 + 360*s4 - 240*s12) + s1*(8*s1 - 5*s2 + 600*s4 - 360*s12) - s12*(360*s1 - 240*s2 + 28800*s4 - 14400*s12) + s4*(600*s1 - 360*s2 + 43200*s4 - 28800*s12)]
if i can insert the value s1-s3, it easier to find another variable

Respuesta aceptada

madhan ravi
madhan ravi el 10 de Jun. de 2020
Editada: madhan ravi el 10 de Jun. de 2020
syms s1 s2 s3
subs(left_ARE,{s1, s2, s3}, {1, 5, 10})

Más respuestas (0)

Categorías

Más información sobre Formula Manipulation and Simplification en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by