Syms function no longer works in a for loop which stores data
Show older comments
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
Answers (1)
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
Categories
Find more on Symbolic Math Toolbox 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!