Is MATLAB giving wrong (symbolic) definite integration??

3 Ansichten (letzte 30 Tage)
Andrew
Andrew am 9 Nov. 2013
Kommentiert: Roger Stafford am 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.

Akzeptierte Antwort

Roger Stafford
Roger Stafford am 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).
  3 Kommentare
Andrew
Andrew am 9 Nov. 2013
Just a question, I can start j from 1. But is there any other method or predefined function in MATLAB which can copy upper triangular results into lower triangular part without loops and all?
Roger Stafford
Roger Stafford am 9 Nov. 2013
M = triu(M,1).'+tril(M,-1);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by