i confuse using syms variable

2 views (last 30 days)
shahin hashemi
shahin hashemi on 15 Jan 2019
Answered: Steven Lord on 15 Jan 2019
dear all
i run the following code :
clear all
N=6; % number of disks
L=0.08; % the length of each segment
x = sym('x', [1 3*N], 'real');
for i=1:N
calf(i)=cos(alf(i)); salf(i)=sin(alf(i));
cbet(i)=cos(bet(i)); sbet(i)=sin(bet(i));
cgam(i)=cos(gam(i)); sgam(i)=sin(gam(i));
ctet(i)=cos(tet(i)); stet(i)=sin(tet(i)); vtet(i)=1-cos(tet(i));
plcl(:,1)=zeros(3,1); % rows for xyz position, cols for disk, 3rd dim for time
for i=1:N
plcl(:,i+1)= L*[(bet(i)*vtet(i))/(tet(i)^2);-(alf(i)*vtet(i))/(tet(i)^2 );(stet(i))/tet(i)];
and i got this error :
The following error occurred converting from sym to double:
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use VPA.
Error in ENERJYplus1 (line 36)
i really appreciated if someone help me that y i got this error and what s the solotion ?
and i should mention that i need to use diff for R at my next step
and i think i could use this code in past ver of matlab

Accepted Answer

Steven Lord
Steven Lord on 15 Jan 2019
The symbolic expression on the right side of the equals sign:
still contains a symbolic variable. When you try assigning into the double array plcl (which is double because it was preallocated using zeros) MATLAB can't evaluate the symbolic expression to get a number. It's as though I asked you the numeric value of sin(z) without telling you what z is. Is it -1, 1, or something inbetween?
Your two main choices:
  1. Substitute values into the symbolic expression using subs so the result is a number, containing no symbolic variables.
  2. Preallocate plcl to be a symbolic array using sym(zeros(3, 1)).

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by