Using subs in a matrix of equations

5 次查看(过去 30 天)
If i have a matrix of eqns, how can i sub in certain letter values now. I am using a live script where the first section creates the matrix, the second section i want to sub in the values of the constants.
%section1
close all; clear; clc;
syms A C0 Dv ka kh kt x1 x2 x3 x4 v1 v2 v3 u1 u2
%each element of the linearizes matrix
f1 = 1/A * (ka*(u1+u2)-C0*sqrt(x1-x2));
f2 = 1/A * (C0*sqrt(x1-x2)-Dv*sqrt(x2)*v1);
f3 = 1/(A*x1) * ((v2-x3)*ka*u1+(v3-x3)*ka*u2);
f4 = 1/(A*x2) * (x3-x4)*C0*sqrt(x1-x2);
AJ = jacobian([f1;f2;f3;f4],[x1 x2 x3 x4])
BJ = jacobian([f1;f2;f3;f4],[u1 u2])
BvJ = jacobian([f1;f2;f3;f4],[v1 v2 v3])
CJ = [0 kh 0 0;
0 0 0 kt]
%section 2
A = 0.785;
Dv = 2.66;
C0 = 0.056;
ka = 0.004;
kh = 2;
kt = 0.1;

采纳的回答

Walter Roberson
Walter Roberson 2021-3-6
%section1
close all; clear; clc;
syms A C0 Dv ka kh kt x1 x2 x3 x4 v1 v2 v3 u1 u2
%each element of the linearizes matrix
f1 = 1/A * (ka*(u1+u2)-C0*sqrt(x1-x2));
f2 = 1/A * (C0*sqrt(x1-x2)-Dv*sqrt(x2)*v1);
f3 = 1/(A*x1) * ((v2-x3)*ka*u1+(v3-x3)*ka*u2);
f4 = 1/(A*x2) * (x3-x4)*C0*sqrt(x1-x2);
AJ = jacobian([f1;f2;f3;f4],[x1 x2 x3 x4])
AJ = 
BJ = jacobian([f1;f2;f3;f4],[u1 u2])
BJ = 
BvJ = jacobian([f1;f2;f3;f4],[v1 v2 v3])
BvJ = 
CJ = [0 kh 0 0;
0 0 0 kt]
CJ = 
%section 2
A = 0.785;
Dv = 2.66;
C0 = 0.056;
ka = 0.004;
kh = 2;
kt = 0.1;
%section 3
subs(AJ)
ans = 
subs(BJ)
ans = 

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by