Accessing entries of symfun
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ali Baig
am 17 Nov. 2020
Beantwortet: Ameer Hamza
am 17 Nov. 2020
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?
0 Kommentare
Akzeptierte Antwort
Setsuna Yuuki.
am 17 Nov. 2020
Bearbeitet: Setsuna Yuuki.
am 17 Nov. 2020
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) % -------- %
0 Kommentare
Weitere Antworten (2)
Walter Roberson
am 17 Nov. 2020
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)
0 Kommentare
Ameer Hamza
am 17 Nov. 2020
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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!