How to carry an unknown variable through computation and solve?
Show older comments
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
Answers (1)
Walter Roberson
on 18 Apr 2016
Replace the
syms x
with
x = sym('x');
or remove the "end" that matches the "function" statement.
1 Comment
Eileen Miller
on 18 Apr 2016
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!