Accessing entries of symfun

3 次查看(过去 30 天)
I am trying to solve a structural mechanics problem for which I have defined
clear all
close all
clc
syms psi(x_1, x_2, x_3)
syms E nu
u_1 = diff(psi, x_1, 1);
u_2 = diff(psi, x_2, 1);
u_3 = diff(psi, x_3, 1);
epsilon_1 = diff(u_1, x_1, 1);
epsilon_2 = diff(u_2, x_2, 1);
epsilon_3 = diff(u_3, x_3, 1);
gamma_12 = diff(u_1, x_2, 1) + diff(u_2, x_1, 1);
gamma_13 = diff(u_1, x_3, 1) + diff(u_3, x_1, 1);
gamma_23 = diff(u_2, x_3, 1) + diff(u_3, x_2, 1);
epsilon = [epsilon_1; epsilon_2; epsilon_3; gamma_23; gamma_13; gamma_12];
C = E / ((1 + nu) * (1 - 2 * nu)) * [1 - nu nu nu 0 0 0; ...
nu 1 - nu nu 0 0 0; ...
nu nu 1 - nu 0 0 0; ...
0 0 0 (1 - 2 * nu) / 2 0 0; ...
0 0 0 0 (1 - 2 * nu) / 2 0; ...
0 0 0 0 0 (1 - 2 * nu) / 2];
sigma = C * epsilon
Since the size of C is 6 x 6 and the size of epsilon is 6 x 1; the order of sigma should be 6 x 1. However when I use
size(sigma)
I get 1 x 1, which does not make sense to me. Also, I want to access individual entries of sigma. How can I do that?

采纳的回答

Setsuna Yuuki.
Setsuna Yuuki. 2020-11-17
编辑:Setsuna Yuuki. 2020-11-17
you can try with formula():
clear all
close all
clc
syms psi(x_1, x_2, x_3)
syms E nu
u_1 = diff(psi, x_1, 1);
u_2 = diff(psi, x_2, 1);
u_3 = diff(psi, x_3, 1);
epsilon_1 = diff(u_1, x_1, 1);
epsilon_2 = diff(u_2, x_2, 1);
epsilon_3 = diff(u_3, x_3, 1);
gamma_12 = diff(u_1, x_2, 1) + diff(u_2, x_1, 1);
gamma_13 = diff(u_1, x_3, 1) + diff(u_3, x_1, 1);
gamma_23 = diff(u_2, x_3, 1) + diff(u_3, x_2, 1);
epsilon = [epsilon_1; epsilon_2; epsilon_3; gamma_23; gamma_13; gamma_12];
C = E / ((1 + nu) * (1 - 2 * nu)) * [1 - nu nu nu 0 0 0; ...
nu 1 - nu nu 0 0 0; ...
nu nu 1 - nu 0 0 0; ...
0 0 0 (1 - 2 * nu) / 2 0 0; ...
0 0 0 0 (1 - 2 * nu) / 2 0; ...
0 0 0 0 0 (1 - 2 * nu) / 2];
sigma = C * epsilon;
sigma = formula(sigma) % -------- %

更多回答(2 个)

Walter Roberson
Walter Roberson 2020-11-17
sigma is a function rather than an array. It is a 1x1 symfun object. It does not have individual entries: it is a formula.
You can invoke the function on symbolic arguments to get back the array that would be the result for those arguments.
Or you can use
feval(symengine, 'op', sigma)

Ameer Hamza
Ameer Hamza 2020-11-17
sigma is a symbolic function. You need to gives inputs to get a 6x1 matrix. For example, check
size(sigma(1,1,1))
For a general case, you can write
sigma = C * epsilon
Sigma = sigma(x_1, x_2, x_3)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by