Double integral problem with function handles to make the program faster instead of using symbolic
31 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ilke
el 3 de Nov. de 2024 a las 21:53
Comentada: Walter Roberson
el 3 de Nov. de 2024 a las 23:32
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 comentarios
Respuesta aceptada
Walter Roberson
el 3 de Nov. de 2024 a las 22:04
Movida: Walter Roberson
el 3 de Nov. de 2024 a las 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 comentarios
Walter Roberson
el 3 de Nov. de 2024 a las 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Numbers and Precision en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!