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.
Unrecognized function or variable 'ksi'.
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.

采纳的回答

Walter Roberson
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 个评论
Ilke
Ilke 2024-11-3,22:57
移动:Walter Roberson 2024-11-3,23:27
So thankful, i thought, i should not use syms ,cause to make it slower. But now, it worked. Thanks :)
Walter Roberson
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)
Error using vertcat
Dimensions of arrays being concatenated are not consistent.

Error in solution>@(ksi,ita)[0;1;(1*(1+ksi)/2)] (line 3)
dTksi = @(ksi,ita) [0;1;(1*(1+ksi)/2)];

Error in solution>@(ksi,ita)((getRow(dTksi(ksi,ita),i)).*(getRow(dTita(ksi,ita),i))) (line 6)
P00_Q00= @(ksi,ita) ((getRow(dTksi(ksi,ita), i)).*(getRow(dTita(ksi,ita), i)));

Error in integral2Calc>tensor (line 240)
Z = FUN(X,Y); NFE = NFE + 1;

Error in integral2Calc>integral2t (line 55)
[Qsub,esub,FIRSTFUNEVAL,NFE] = tensor(thetaL,thetaR,phiB,phiT,[],[], ...

Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);

Error in integral2 (line 105)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
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 CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by