substitute numeric matrix into symbolic expression

hi, im using symbolic matrixes (WW is 2by 1 and x is 3 by 1) to calculate the sum of the product of WW*x(1) +WW*x(2)... and put it in a matrix,this works fine but when i try to substitute the symbolic matrixes by numeric ones the result remains in function of WW and x even after WW and x are numeric in workspace and when i sue eval() it says undefind function or variable WW1 wich is awkward cause i can see it there in workspace
%initiate data
P=3;
m=1;
n=2;
N=1;
P=3;
m=1;
n=2;
N=1;
u=0;%u is the middle variant
%definning symbolic variables (matrix variables)
WW=sym('WW', [n,m])
x=sym('x', [P,m])
for p=1:P
for j=1:n
u=0
for k=1:m
u=u+WW(j,k)*x(p,k) %calculation of sum
end
net(p,j)=u
end
end
%definning symbolic variables (matrix variables)
subs(net,WW(1),double(1))
subs(net,x(1),1)
%another try
x=[1 ;1; 1]
WW=[1 ;1]
ev= eval(net)

1 comentario

Stephen23
Stephen23 el 20 de Ag. de 2017
Editada: Stephen23 el 20 de Ag. de 2017
@aziz dattebayou: Please do not add comments and screen shots in Answers. Please do not accept your own answer that is not an answer to the question but only includes a screen shot. Please add any screenshots and new information in comments.
The Answers are for answering the question. Accepting an answer tells everyone that that answer resolves your question. So when you accept your own "Answer" then you are telling everyone that you do not need any more help.
I moved your screenshot to your question and deleted your "Answer" that was not really an answer.

Iniciar sesión para comentar.

 Respuesta aceptada

You do not have WW1 in your workspace. You have WW, which is a 2 x 1 vector containing the symbols WW1 and WW2.
Your line
subs(net,WW(1),double(1))
does not change the variable net : it does a substitution and emits a copy of the net in which the substitutions have been done, and then that copy is displayed because that is the default behavior in MATLAB when you compute something and do not have a ";" after the expression. If you want to change net then you need to assign the output to net
You should never eval() a symbolic expression. Symbolic expressions are coded in a language that looks very similar to MATLAB, but which are not quite MATLAB code. If you want to have the value of variables inserted to replace the symbols with the same name in a symbolic expression, you should use subs(), possibly followed by double() if you want the result as a double.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by