Double integral problem with function handles to make the program faster instead of using symbolic
조회 수: 31 (최근 30일)
이전 댓글 표시
Hello Sir, I am trying to solve a plate problem with Rayleigh. Instead of doing all the double integrals with symbolic functions, i would like to make it with function handles. Symbolic tools are taking so much. May you please check me my code? There is a vector (lets assume, it is 3*1) I would like to take each of elements, respectively and make it double integral (From ksi=-1 to1, ita =-1 to 1). But it is giving error.I really preciate if you could help me to take integral from ksi =-1 to 1, and ita=-1 to 1. My regards.
Here is my code:
clc
clear all
i=3; %actually this will be loop from i=1: 10 (but i will not store)
dTksi = @(ksi,ita) [0;1;(1*(1+ksi)/2)];
dTita =@(ksi,ita,a) [0;1;1*(1*(1+ita)/2)];
getRow = @(data, rowNum) data(rowNum, :); % Helper function
P00_Q00= @(ksi,ita) ((getRow(dTksi(ksi,ita), i)).*(getRow(dTita(ksi,ita), i)));
ff=(int(int(P00_Q00(ksi,ita),-1,1),-1,1)) % it is not calculating.
dfuita=@(ksi,ita) (-2*ita);
ddfuksi_P00_Q00= @(ksi,ita) dfuita(ksi,ita).*P00_Q00(ksi,ita); %it is calculating
%fun = integral2(@(ksi,ita) dfuita(ksi,ita).*(1-ita.^2),-1,1,-1,1)
fun=(int(int(dfuita(ksi,ita).*P00_Q00(ksi,ita),-1,1),-1,1)) % it is not calculating.
댓글 수: 0
채택된 답변
Walter Roberson
2024년 11월 3일 22:04
이동: Walter Roberson
2024년 11월 3일 22:04
ksi and ita are undefined at that point. If you define them with syms then the integration works.
syms ksi ita
i=3; %actually this will be loop from i=1: 10 (but i will not store)
dTksi = @(ksi,ita) [0;1;(1*(1+ksi)/2)];
dTita =@(ksi,ita,a) [0;1;1*(1*(1+ita)/2)];
getRow = @(data, rowNum) data(rowNum, :); % Helper function
P00_Q00= @(ksi,ita) ((getRow(dTksi(ksi,ita), i)).*(getRow(dTita(ksi,ita), i)));
ff=(int(int(P00_Q00(ksi,ita),-1,1),-1,1)) % it is not calculating.
dfuita=@(ksi,ita) (-2*ita);
ddfuksi_P00_Q00= @(ksi,ita) dfuita(ksi,ita).*P00_Q00(ksi,ita); %it is calculating
%fun = integral2(@(ksi,ita) dfuita(ksi,ita).*(1-ita.^2),-1,1,-1,1)
fun=(int(int(dfuita(ksi,ita).*P00_Q00(ksi,ita),-1,1),-1,1)) % it is not calculating.
댓글 수: 2
Walter Roberson
2024년 11월 3일 23:32
If you try to switch to numeric integration
i=3; %actually this will be loop from i=1: 10 (but i will not store)
dTksi = @(ksi,ita) [0;1;(1*(1+ksi)/2)];
dTita =@(ksi,ita,a) [0;1;1*(1*(1+ita)/2)];
getRow = @(data, rowNum) data(rowNum, :); % Helper function
P00_Q00= @(ksi,ita) ((getRow(dTksi(ksi,ita), i)).*(getRow(dTita(ksi,ita), i)));
ff = integral2(P00_Q00,-1,1,-1,1)
This is because integral2() passes in arrays of values for the parameters, so the [0;1;(1*(1+ksi)/2)] would try to horzcat between 0, 1, and an array of values induced by ksi, and that would fail.
You would have to switch to using arrayfun() in P00_Q00 which will slow things down notably.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Numbers and Precision에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!