Accessing entries of symfun

조회 수: 19 (최근 30일)
Ali Baig
Ali Baig 2020년 11월 17일
답변: Ameer Hamza 2020년 11월 17일
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)

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by