Solve a system of symbolic variables
4 次查看(过去 30 天)
显示 更早的评论
Hi,
I have been trying hard at this for a while now. Does anybody know if there is some way to solve symbolic variables in a matrix, resulting in a double format?
I want to solve for the unknowns of F and d. The amount of unknowns depends on the values specified in the input:
% This program calculates any straight equal-length element analysis
% for a bar with two fixed ends
syms Freact1 Freact2;
A = input('Cross-sectional area (mm^2): ');
E = input('Elastic Modulus (MPa): ');
L = input('Length of the system (mm): ');
num_ele = input('Enter the number of elements to be analyzed: ');
num_nodes = num_ele + 1;
k = (E*A)/(L/num_ele);
F = zeros(num_nodes,1);
d = zeros(num_nodes,1);
d(1) = 0; d(num_nodes) = 0;
F1 = vpa(Freact1); Fend = vpa(Freact2);
F(1) = F1; F(num_nodes) = Fend;
disp(' ');
for i = 2:num_ele
str = sprintf('Node %d: ', i);
disp(str);
F(i) = input('Enter the force at the node (N): ');
disp(' ');
end
glbl_stiff = 0*diag(num_nodes,num_nodes-1) + 2*eye(num_nodes);
glbl_stiff(1,1) = 1; glbl_stiff(num_nodes,num_nodes) = 1;
for j = 1:num_ele
glbl_stiff(j,j+1) = -1;
glbl_stiff(j+1,j) = -1;
end
glbl_stiff = k*glbl_stiff;
F = glbl_stiff*d
d = F\glbl_stiff
and the error that always results:
The following error occurred converting from sym to
double:
Error using mupadmex
Error in MuPAD command: DOUBLE cannot convert the
input expression into a double array.
If the input expression contains a symbolic
variable, use the VPA function instead.
Error in FEM_IA1 (line 20)
F(1) = F1; F(num_nodes) = Fend;
It's confusing because I did use the VPA function. It just seems like nothing's working.. any ideas would greatly be appreciated.
Thanks, Ian
0 个评论
回答(3 个)
Star Strider
2012-10-16
编辑:Star Strider
2012-10-16
The variables Freact1 and Freact2 in that line are symbolic variables. You haven't assigned any numeric values to them.
14 个评论
Matt Fig
2012-10-16
Use symbolic arrays instead:
F = sym(zeros(num_nodes,1));
d = sym(zeros(num_nodes,1));
3 个评论
Phan HaNhut
2014-1-26
if memory of computer is slow, code can not end? (matlab: "busy") And there is not any result?
I have to add more RAM?
Walter Roberson
2014-1-26
If your memory is limited, then you can speed up operations by turning off virtual memory (or configuring it to be size 0). Swapping memory to disk is very very slow, and my practical experience on MS Windows systems is that once you swap enough program memory to disk then you cannot make any progress because you run into "thrashing" (part of memory you need for the calculation is swapped out in order to bring in something else you need, but then that has to get swapped out in order to bring the first back in in order to proceed, but then that needs... etc.) Turning off virtual memory would result in the calculation failing cleanly with complaints about insufficient memory instead of running for days getting nowhere.
Expanding physical memory is usually good. You may need to switch to a 64 bit operating system (with the extra memory) to make real progress.
Ian Wood
2012-10-17
3 个评论
Star Strider
2012-10-18
Scanning the book you referred me to earlier (the discussions on pages 46-7), it seems that you would solve independently for the forces with zero (or other defined) displacements and then for the displacements with known forces as separate procedures.
So you would for instance solve for d2 as a linear equation with a force of 1000, then use sparse matrix techniques to solve for F1 and F3 with displacements = 0. That seems to be what the book suggests, and that's certainly how I would do it. It doesn't seem mathematically possible to do both simultaneously, since that would mean having unknowns on both sides of the equation.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Special Values 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!