Is MATLAB giving wrong (symbolic) definite integration??

2 ビュー (過去 30 日間)
Andrew
Andrew 2013 年 11 月 9 日
コメント済み: Roger Stafford 2013 年 11 月 9 日
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
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 件のコメント
Andrew
Andrew 2013 年 11 月 9 日
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 2013 年 11 月 9 日
M = triu(M,1).'+tril(M,-1);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by