Is MATLAB giving wrong (symbolic) definite integration??

2 views (last 30 days)
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
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.

Accepted Answer

Roger Stafford
Roger Stafford on 9 Nov 2013
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).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!