How to carry an unknown variable through computation and solve?
Afficher commentaires plus anciens
I am trying to carry an unknown variable through a couple steps of computation and solve for the unknown. I have written a "dummy" code to test my approach, and it works:
syms x
SS = cell(1,3)
G = 1;
DS = [0 1 2; 3 4 5; 6 7 8];
for n = 1:1
SS{n} = [n n n; n n n; n n n];
SSTSC = SS{n}+ x* DS;
DDS = 0
for i = 1:3
for j = 1:3
DDS = DDS + SSTSC(i,j)*SSTSC(i,j)
end
end
eqn = (1/2)*DDS -(1/3)*G == 0
solx = solve(eqn,x)
end
However, when I try to apply this approach to my code:
syms x
%mean of the trial stress tensor
MDS = (DSTST{k}(1) + DSTST{k}(2) + DSTST{k}(3))/3;
%deviator of the trail stress tensor
DS = [0 DSTST{k}(4)-MDS DSTST{k}(6)-MDS;
DSTST{k}(4)-MDS 0 DSTST{k}(5)-MDS;
DSTST{k}(6)-MDS DSTST{k}(5)-MDS 0]
%Deviatoric Stress Tensor for contact stress state
SC = S{k}+ x* DS
%Compute S*S for contract stress state
SSC = 0;
for i=1:3
for j=1:3
SSC = SSC+ SC(i,j)*SC(i,j)
end
end
eqn =(1/2)*SSC-(1/3)*SIG{k} == 0
R = solve(eqn,x)
I am getting error:
Error using assignin
Attempt to add "x" to a static workspace.
See MATLAB Programming, Restrictions on Assigning to
Variables for details.
Error in syms (line 66)
assignin('caller',x,sym(x));
Error in J2FlowTheory (line 119)
syms x
Réponses (1)
Walter Roberson
le 18 Avr 2016
Replace the
syms x
with
x = sym('x');
or remove the "end" that matches the "function" statement.
1 commentaire
Eileen Miller
le 18 Avr 2016
Catégories
En savoir plus sur Common Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!