Accessing entries of symfun

3 visualizaciones (últimos 30 días)
Ali Baig
Ali Baig el 17 de Nov. de 2020
Respondida: Ameer Hamza el 17 de Nov. de 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?

Respuesta aceptada

Setsuna Yuuki.
Setsuna Yuuki. el 17 de Nov. de 2020
Editada: Setsuna Yuuki. el 17 de Nov. de 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) % -------- %

Más respuestas (2)

Walter Roberson
Walter Roberson el 17 de Nov. de 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)

Ameer Hamza
Ameer Hamza el 17 de Nov. de 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)

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by