double integral problem pleas help
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
hello this is my loop for integration and asseble a matrix m but not works. what is my mistake ?
syms x %xi
syms y %eta
%
fun(1) = -.25.*(1-x).*(1-y).*(1 + x + y) ;
fun(2) = 0.5.*(1 - x.^2).*(1-y) ;
fun(3) = -.25*(1+x).*(1-y).*(1 - x + y) ;
fun(4) = 0.5.*(1+x).*(1 - y.^2) ;
fun(5) = -.25.*(1+x).*(1+y).*(1 - x - y) ;
fun(6) = 0.5.*(1 - x.^2).*(1+y) ;
fun(7) = -.25.*(1-x).*(1+y).*(1 + x - y) ;
fun(8) = 0.5.*(1-x).*(1 - y.^2) ;
m=zeros(8,8) ;
k=1 ;
for i=1:8
for j=1:8
a(k)=fun(i).*fun(j) ;
func=@(x,y) a(k);
l=integral2(func,-1,1,-1,1) ;
m(i,j)=m(i,j)+l ;
k=k+1 ;
end
end
1 Kommentar
Sara Boznik
am 15 Aug. 2020
Hi! Tell me if in this fun (n) you have to put for both x and y the same value, so I mean fun (1) where is x=1 and y=1?
Antworten (1)
Star Strider
am 15 Aug. 2020
The integral2 function is not appropriate for symbolic arguments.
Try this version of the loop instead:
m=zeros(8,8) ;
k=1 ;
for i=1:8
for j=1:8
a(k)=fun(i).*fun(j) ;
func=@(x,y) a(k);
l=int(int(func,x,-1,1),y,-1,1) ;
m(i,j)=m(i,j)+l ;
k=k+1 ;
end
end
The rest of the code is unchanged.
2 Kommentare
Sara Boznik
am 15 Aug. 2020
I get error with fun (1), I think there is something wrong.
Star Strider
am 15 Aug. 2020
It runs for me without error in R2020a, and with:
M = vpa(m,5)
produces:
M =
[ 0.13333, -0.13333, 0.044444, -0.17778, 0.066667, -0.17778, 0.044444, -0.13333]
[ -0.13333, 0.71111, -0.13333, 0.44444, -0.17778, 0.35556, -0.17778, 0.44444]
[ 0.044444, -0.13333, 0.13333, -0.13333, 0.044444, -0.17778, 0.066667, -0.17778]
[ -0.17778, 0.44444, -0.13333, 0.71111, -0.13333, 0.44444, -0.17778, 0.35556]
[ 0.066667, -0.17778, 0.044444, -0.13333, 0.13333, -0.13333, 0.044444, -0.17778]
[ -0.17778, 0.35556, -0.17778, 0.44444, -0.13333, 0.71111, -0.13333, 0.44444]
[ 0.044444, -0.17778, 0.066667, -0.17778, 0.044444, -0.13333, 0.13333, -0.13333]
[ -0.13333, 0.44444, -0.17778, 0.35556, -0.17778, 0.44444, -0.13333, 0.71111]
Nothing appears to be wrong when I run it.
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!