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!