Syms function no longer works in a for loop which stores data
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
x= NaN(2,1);
syms F q L;
for i = 1:2
for j = 1:2
K(i,j) = F*(L^(i+j+1))*((((i+1)*(j+1))/(i+j+1))+ ((i*j)/(i+j-1))) - (((2*i*j)+i+j)/(i+j)); % K matrix for the second iteration
x(i,1) = q*(L^(i+2))*((1/(i+3)) - (1/(i+2))); % F vector for the second iteration
end
end
% Solving of the second linear equation of form Kc+F=0 to obtain {c2}
c2 = linsolve(K,-x);
I am getting an error saying it cant convert from sym to double whenever I stry to store K in a matrix and F in its vector. How can this be fixed?
Cheers
0 comentarios
Respuestas (1)
Steven Lord
el 2 de Dic. de 2020
If you try to do something like the following:
%{
syms x
F = 0;
F(2) = x;
%}
What numeric value should be stored in F(2) after that code runs? The answer is that x is symbolic and cannot be converted into a numeric value so this will throw an error. If you want to store symbolic data into an array preallocate that array to be a symbolic array from the start.
syms x
F = sym(0);
F(2) = x
G = sym(zeros(1, 10));
for k = 1:10
G(k) = x.^k;
end
G
0 comentarios
Ver también
Categorías
Más información sobre Conversion Between Symbolic and Numeric en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!