Is MATLAB giving wrong (symbolic) definite integration??
2 次查看(过去 30 天)
显示 更早的评论
Hello, I am trying to compute a definite integral of symbolic array. I did this in two ways: (1) using function int() (2)using integral(). However I am facing problem in both cases and I am not understanding why this is happening. Here is my code:
syms xlc
ke=[2000000*(0.16*xlc - 0.6)^2, -2000000*(0.32*xlc - 0.8)*(0.16*xlc - 0.6), 2000000*(0.16*xlc - 0.2)*(0.16*xlc - 0.6); -2000000*(0.32*xlc - 0.8)*(0.16*xlc - 0.6), 2000000*(0.32*xlc - 0.8)^2, -2000000*(0.16*xlc - 0.2)*(0.32*xlc - 0.8);2000000*(0.16*xlc - 0.2)*(0.16*xlc - 0.6), -2000000*(0.16*xlc - 0.2)*(0.32*xlc - 0.8), 2000000*(0.16*xlc - 0.2)^2];
%ke is 3x3 symbolic matrix and it is symmetric
a=0; %lower bound of integration
b=5; %upper bound of integration
%Integration of each element in matrix ke, integration ke(i,j) from a to b
for i=1:1:3
for j=i:1:3
%t1=matlabFunction(ke(i,j)); %see COMMENT 1 below
ke_num(i,j)=double(int(ke(i,j),xlc,a,b));
end
end
This is very straightforward code. As ke is symmetric, I expect integration ke_num matrix to be symmetric. However, I get ke_num as upper triangular matrix. What is wrong? I am not able to find. %COMMENT 1: One thing I know is we should vectorize function. How to achieve this in this program? Just using matlabFunction() does not crate that. Any ideas, suggestions? Thanks.
0 个评论
采纳的回答
Roger Stafford
2013-11-9
Your inner for-loop is written
for j=i:1:3
with the lower value as 'i' rather that 1. This of course gives you an upper triangular matrix because you must always have j>=i. With a symmetric matrix such as yours this is a more efficient method but you must copy the result into both ke_num(i,j) and ke_num(j,i).
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!