Why did this error message appear?
174 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Unable to perform assignment because value of type 'sym' is not convertible to 'double'.
line10.Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to
substitute values for variables.
- m=600:1200;
- r=ones(20,601);t=ones(20,601);
- n0=1;
- n1=1.75;d1=125;
- n2=2.5;d2=87.5;
- n3=1.45;
- k=2*pi./m;
- e1=n1*d1*k;e2=n2*d2*k;
- x1= sym('x1',[1,601]);
- r(1,:)=(n0+n1)/(2*n1)+(n1-n0)/(2*n1)*x1;
- t(1,:)=(n1-n0)/(2*n1)+(n1+n0)/(2*n1)*x1;
- for i=2:20
- if rem(i,2)==0
- t(i,:)=(n1+n2)/(2*n2)*t(i-1)*exp(2*e1*1i)+(n1-n2)/(2*n2)*r(i-1)*exp(-2*e1*1i);
- r(i,:)=(-n1+n2)/(2*n2)*t(i-1)*exp(2*e1*1i)+(n2+n1)/(2*n2)*r(i-1)*exp(-2*e1*1i);
- else
- t(i,:)=(n1+n2)/(2*n1)*t(i-1)*exp(2*e2*1i)+(n2-n1)/(2*n1)*r(i-1)*exp(-2*e2*1i);
- r(i,:)=(-n2+n1)/(2*n1)*t(i-1)*exp(2*e2*1i)+(n2+n1)/(2*n1)*r(i-1)*exp(-2*e2*1i);
- end
- end
- solve(r(20,:),x);
- T=t(20,:).*conj(t(20,:))*n3;
- plot(m,T);
0 comentarios
Respuestas (1)
Steven Lord
el 14 de Nov. de 2021
Since r is a double array, anything that you want to assign into it must be a double array or convertible into a double array.
In this example:
r = 1:10
syms x y
z = x.^2+y.^2
what is the double precision value of z? Without having values for x and y we cannot convert z into a double array, and so trying to store z inside r won't work.
r(1) = z
You could make r a symbolic array from the start, or you could substitute values for x and y into z (thus making z a plain number.)
rsym = sym(1:10)
Ver también
Categorías
Más información sobre Conversion Between Symbolic and Numeric en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!