# Is MATLAB giving wrong (symbolic) definite integration??

2 views (last 30 days)
Andrew on 9 Nov 2013
Commented: Roger Stafford on 9 Nov 2013
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.

Roger Stafford on 9 Nov 2013
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).
Roger Stafford on 9 Nov 2013
M = triu(M,1).'+tril(M,-1);