You are on page 1of 23

>> n=3;

m=n+2;
ns=m*m;
p=zeros(2,ns);
s=1;
h=1/(n+1);
%sommets internes
for j= 1:n
for i= 1:n
p(1,s)=i*h;
p(2,s)=j*h;
s=s+1;
end
end
%sommets axes de x
for i= 0:(n+1)
p(1,s)=i*h;
p(2,s)=0;
s=s+1;
end
%sommets axes de y
for j= 1:n
p(1,s)=0;
p(2,s)=j*h;
s=s+1;
end
%sommets axes de x=(n+1)
for j= 1:n
p(1,s)=(n+1)*h;
p(2,s)=j*h;
s=s+1;
end
%sommets axes de y=(n+1)
for i= 0:(n)
p(1,s)=i*h;
p(2,s)=(n+1)*h;
s=s+1;
end

>> p

p =

Columns 1 through 12

0.2500 0.5000 0.7500 0.2500 0.5000 0.7500 0.2500 0.5000


0.7500 0 0.2500 0.5000
0.2500 0.2500 0.2500 0.5000 0.5000 0.5000 0.7500 0.7500
0.7500 0 0 0

Columns 13 through 24

0.7500 1.0000 0 0 0 1.0000 1.0000 1.0000


0 0.2500 0.5000 0.7500
0 0 0.2500 0.5000 0.7500 0.2500 0.5000 0.7500
1.0000 1.0000 1.0000 1.0000

Column 25
0
0

>> n=3;
m=n+1;
nt=2*m*m;
t=zeros(3,nt);
k=1;
%partie 1
for j=1:(n-1)
for i=1:(n-1)
t(1,k)=i+(j-1)*n;
t(2,k)=i+(j-1)*n+1;
t(3,k)=i+j*n+1;
k=k+1;
t(1,k)=i+(j-1)*n;
t(2,k)=i+j*n+1;
t(3,k)=i+j*n;
k=k+1;
end
end
%partie 2
t(1,k)=n^2+1;
t(2,k)=n^2+2;
t(3,k)=1;
k=k+1;
t(1,k)=n^2+1;
t(2,k)=1;
t(3,k)=n^2+3+n;
k=k+1;
%partie 3
for i=1:n-1
t(1,k)=n^2+1+i;
t(2,k)=n^2+2+i;
t(3,k)=i+1;
k=k+1;
t(1,k)=n^2+1+i;
t(2,k)=i+1;
t(3,k)=i;
k=k+1;
end
%partie 4
for i=n:n
t(1,k)=n^2+1+i;
t(2,k)=n^2+2+i;
t(3,k)=n^2+2*n+3;
k=k+1;
t(1,k)=n^2+1+i;
t(2,k)=n^2+2*n+3;
t(3,k)=n;
k=k+1;
end
%partie 5
for j=1:n-1
t(1,k)=n^2+n+3+(j-1);
t(2,k)=(j-1)*n+1;
t(3,k)=j*n+1;
k=k+1;
t(1,k)=n^2+n+3+(j-1);
t(2,k)=j*n+1;
t(3,k)=n^2+n+3+j;
k=k+1;
end
%partie 6
for j=1:n-1
t(1,k)=j*n;
t(2,k)=n^2+2*n+3+(j-1);
t(3,k)=n^2+2*n+3+j;
k=k+1;
t(1,k)=j*n;
t(2,k)=n^2+2*n+3+j;
t(3,k)=(j+1)*n;
k=k+1;
end
%partie 7
t(1,k)=n^2+2*n+2;
t(2,k)=n^2+-n+1;
t(3,k)=n^2+3*n+4;
k=k+1;
t(1,k)=n^2+2*n+2;
t(2,k)=n^2+3*n+4;
t(3,k)=n^2+3*n+3;
k=k+1;
%partie 8
for i=1:n-1
t(1,k)=n^2-n+i;
t(2,k)=n^2-n+(1+i);
t(3,k)=n^2+3*n+i+4;
k=k+1;
t(1,k)=n^2-n+i;
t(2,k)=n^2+3*n+i+4;
t(3,k)=n^2+3*n+i+3;
k=k+1;
end
%partie 9
t(1,k)=n^2;
t(2,k)=n^2+3*n+2;
t(3,k)=n^2+4*n+4;
k=k+1;
t(1,k)=n^2;
t(2,k)=n^2+4*n+4;
t(3,k)=n^2+4*n+3;
k=k+1;
>> t

t =

Columns 1 through 20

1 1 2 2 4 4 5 5 10 10 11 11 12
12 13 13 15 15 16 16
2 5 3 6 5 8 6 9 11 1 12 2 13
3 14 18 1 4 4 7
5 4 6 5 8 7 9 8 1 15 2 1 3
2 18 3 4 16 7 17

Columns 21 through 32
3 3 6 6 17 17 7 7 8 8 9 9
18 19 19 20 7 22 8 23 9 24 20 25
19 6 20 9 22 21 23 22 24 23 25 24

>> A=zeros(np,np);
for k=1:nt
sommets=t(1:3,k)
x=p(1,sommets);
y=p(2,sommets);
area=polyarea(x,y);
b=[y(2)-y(3);y(3)-y(1);y(1)-y(2)]/(2*area);
c=[x(3)-x(2);x(1)-x(3);x(2)-x(1)]/(2*area);
AK=(b*b'+c*c')*area;
A(sommets,sommets)=A(sommets,sommets)+AK;
end;

Undefined function or variable 'np'.

A=zeros(np,np);
for k=1:nt
sommets=t(1:3,k)
x=p(1,sommets);
y=p(2,sommets);
area=polyarea(x,y);
b=[y(2)-y(3);y(3)-y(1);y(1)-y(2)]/(2*area);
c=[x(3)-x(2);x(1)-x(3);x(2)-x(1)]/(2*area);
AK=(b*b'+c*c')*area;
A(sommets,sommets)=A(sommets,sommets)+AK;
end;
Undefined function or variable 'np'.

>> A=zeros(ns,ns);
for k=1:nt
sommets=t(1:3,k)
x=p(1,sommets);
y=p(2,sommets);
area=polyarea(x,y);
b=[y(2)-y(3);y(3)-y(1);y(1)-y(2)]/(2*area);
c=[x(3)-x(2);x(1)-x(3);x(2)-x(1)]/(2*area);
AK=(b*b'+c*c')*area;
A(sommets,sommets)=A(sommets,sommets)+AK;
end;

sommets =

1
2
5

sommets =

1
5
4

sommets =
2
3
6

sommets =

2
6
5

sommets =

4
5
8

sommets =

4
8
7

sommets =

5
6
9

sommets =

5
9
8

sommets =

10
11
1

sommets =

10
1
15

sommets =

11
12
2

sommets =

11
2
1

sommets =

12
13
3

sommets =

12
3
2

sommets =

13
14
18

sommets =

13
18
3

sommets =

15
1
4

sommets =

15
4
16

sommets =

16
4
7
sommets =

16
7
17

sommets =

3
18
19

sommets =

3
19
6

sommets =

6
19
20

sommets =

6
20
9

sommets =

17
7
22

sommets =

17
22
21

sommets =

7
8
23

sommets =

7
23
22

sommets =

8
9
24

sommets =

8
24
23

sommets =

9
20
25

sommets =

9
25
24

>> A

A =

Columns 1 through 12

4.0000 -1.0000 0 -1.0000 0 0 0 0


0 0 -1.0000 0
-1.0000 4.0000 -1.0000 0 -1.0000 0 0 0
0 0 0 -1.0000
0 -1.0000 4.0000 0 0 -1.0000 0 0
0 0 0 0
-1.0000 0 0 4.0000 -1.0000 0 -1.0000 0
0 0 0 0
0 -1.0000 0 -1.0000 4.0000 -1.0000 0 -1.0000
0 0 0 0
0 0 -1.0000 0 -1.0000 4.0000 0 0
-1.0000 0 0 0
0 0 0 -1.0000 0 0 4.0000 -1.0000
0 0 0 0
0 0 0 0 -1.0000 0 -1.0000 4.0000
-1.0000 0 0 0
0 0 0 0 0 -1.0000 0 -1.0000
11.3333 0 0 0
0 0 0 0 0 0 0 0
0 1.0000 -0.5000 0
-1.0000 0 0 0 0 0 0 0
0 -0.5000 2.0000 -0.5000
0 -1.0000 0 0 0 0 0 0
0 0 -0.5000 2.0000
0 0 -1.0000 0 0 0 0 0
0 0 0 -0.5000
0 0 0 0 0 0 0 0
0 0 0 0
-1.0000 0 0 0 0 0 0 0
0 -0.5000 0 0
0 0 0 -1.0000 0 0 0 0
0 0 0 0
0 0 0 0 0 0 -1.0000 0
0 0 0 0
0 0 -1.0000 0 0 0 0 0
0 0 0 0
0 0 0 0 0 -1.0000 0 0
0 0 0 0
0 0 0 0 0 0 0 0
-4.0000 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 -1.0000 0
0 0 0 0
0 0 0 0 0 0 0 -1.0000
0 0 0 0
0 0 0 0 0 0 0 0
-4.0000 0 0 0
0 0 0 0 0 0 0 0
-1.3333 0 0 0

Columns 13 through 24

0 0 -1.0000 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0
-1.0000 0 0 0 0 -1.0000 0 0
0 0 0 0
0 0 0 -1.0000 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 -1.0000 0
0 0 0 0
0 0 0 0 -1.0000 0 0 0
0 -1.0000 0 0
0 0 0 0 0 0 0 0
0 0 -1.0000 0
0 0 0 0 0 0 0 -4.0000
0 0 0 -4.0000
0 0 -0.5000 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0
-0.5000 0 0 0 0 0 0 0
0 0 0 0
2.0000 -0.5000 0 0 0 0 0 0
0 0 0 0
-0.5000 1.0000 0 0 0 -0.5000 0 0
0 0 0 0
0 0 2.0000 -0.5000 0 0 0 0
0 0 0 0
0 0 -0.5000 2.0000 -0.5000 0 0 0
0 0 0 0
0 0 0 -0.5000 2.0000 0 0 0
-0.5000 0 0 0
0 -0.5000 0 0 0 2.0000 -0.5000 0
0 0 0 0
0 0 0 0 0 -0.5000 2.0000 -0.5000
0 0 0 0
0 0 0 0 0 0 -0.5000 4.0000
0 0 0 0
0 0 0 0 -0.5000 0 0 0
1.0000 -0.5000 0 0
0 0 0 0 0 0 0 0
-0.5000 2.0000 -0.5000 0
0 0 0 0 0 0 0 0
0 -0.5000 2.0000 -0.5000
0 0 0 0 0 0 0 0
0 0 -0.5000 4.0000
0 0 0 0 0 0 0 0.5000
0 0 0 0.5000

Column 25

0
0
0
0
0
0
0
0
-1.3333
0
0
0
0
0
0
0
0
0
0
0.5000
0
0
0
0.5000
0.3333

>> end;
end;
?
Error: Illegal use of reserved keyword "end".

>> np=size(p,2);
nt=size(t,2);
M=sparse(ns,ns);
for k=1:nt
sommets=t(1:3,k)
x=p(1,sommets);
y=p(2,sommets);
area=polyarea(x,y);
MK=[2 1 1;1 2 1;1 1 2]/12*area;
M(sommets,sommets)=M(sommets,sommets)+MK;
end;

sommets =

1
2
5

sommets =

1
5
4

sommets =

2
3
6

sommets =

2
6
5

sommets =

4
5
8

sommets =

4
8
7

sommets =

5
6
9

sommets =
5
9
8

sommets =

10
11
1

sommets =

10
1
15

sommets =

11
12
2

sommets =

11
2
1

sommets =

12
13
3

sommets =

12
3
2

sommets =

13
14
18

sommets =

13
18
3

sommets =

15
1
4

sommets =

15
4
16

sommets =

16
4
7

sommets =

16
7
17

sommets =

3
18
19

sommets =

3
19
6

sommets =

6
19
20

sommets =

6
20
9
sommets =

17
7
22

sommets =

17
22
21

sommets =

7
8
23

sommets =

7
23
22

sommets =

8
9
24

sommets =

8
24
23

sommets =

9
20
25

sommets =

9
25
24

>> M

M =
(1,1) 0.0312
(2,1) 0.0052
(4,1) 0.0052
(5,1) 0.0052
(10,1) 0.0052
(11,1) 0.0052
(15,1) 0.0052
(1,2) 0.0052
(2,2) 0.0312
(3,2) 0.0052
(5,2) 0.0052
(6,2) 0.0052
(11,2) 0.0052
(12,2) 0.0052
(2,3) 0.0052
(3,3) 0.0312
(6,3) 0.0052
(12,3) 0.0052
(13,3) 0.0052
(18,3) 0.0052
(19,3) 0.0052
(1,4) 0.0052
(4,4) 0.0312
(5,4) 0.0052
(7,4) 0.0052
(8,4) 0.0052
(15,4) 0.0052
(16,4) 0.0052
(1,5) 0.0052
(2,5) 0.0052
(4,5) 0.0052
(5,5) 0.0312
(6,5) 0.0052
(8,5) 0.0052
(9,5) 0.0052
(2,6) 0.0052
(3,6) 0.0052
(5,6) 0.0052
(6,6) 0.0312
(9,6) 0.0052
(19,6) 0.0052
(20,6) 0.0052
(4,7) 0.0052
(7,7) 0.0312
(8,7) 0.0052
(16,7) 0.0052
(17,7) 0.0052
(22,7) 0.0052
(23,7) 0.0052
(4,8) 0.0052
(5,8) 0.0052
(7,8) 0.0052
(8,8) 0.0312
(9,8) 0.0052
(23,8) 0.0052
(24,8) 0.0052
(5,9) 0.0052
(6,9) 0.0052
(8,9) 0.0052
(9,9) 0.0521
(20,9) 0.0104
(24,9) 0.0104
(25,9) 0.0156
(1,10) 0.0052
(10,10) 0.0104
(11,10) 0.0026
(15,10) 0.0026
(1,11) 0.0052
(2,11) 0.0052
(10,11) 0.0026
(11,11) 0.0156
(12,11) 0.0026
(2,12) 0.0052
(3,12) 0.0052
(11,12) 0.0026
(12,12) 0.0156
(13,12) 0.0026
(3,13) 0.0052
(12,13) 0.0026
(13,13) 0.0156
(14,13) 0.0026
(18,13) 0.0052
(13,14) 0.0026
(14,14) 0.0052
(18,14) 0.0026
(1,15) 0.0052
(4,15) 0.0052
(10,15) 0.0026
(15,15) 0.0156
(16,15) 0.0026
(4,16) 0.0052
(7,16) 0.0052
(15,16) 0.0026
(16,16) 0.0156
(17,16) 0.0026
(7,17) 0.0052
(16,17) 0.0026
(17,17) 0.0156
(21,17) 0.0026
(22,17) 0.0052
(3,18) 0.0052
(13,18) 0.0052
(14,18) 0.0026
(18,18) 0.0156
(19,18) 0.0026
(3,19) 0.0052
(6,19) 0.0052
(18,19) 0.0026
(19,19) 0.0156
(20,19) 0.0026
(6,20) 0.0052
(9,20) 0.0104
(19,20) 0.0026
(20,20) 0.0260
(25,20) 0.0078
(17,21) 0.0026
(21,21) 0.0052
(22,21) 0.0026
(7,22) 0.0052
(17,22) 0.0052
(21,22) 0.0026
(22,22) 0.0156
(23,22) 0.0026
(7,23) 0.0052
(8,23) 0.0052
(22,23) 0.0026
(23,23) 0.0156
(24,23) 0.0026
(8,24) 0.0052
(9,24) 0.0104
(23,24) 0.0026
(24,24) 0.0260
(25,24) 0.0078
(9,25) 0.0156
(20,25) 0.0078
(24,25) 0.0078
(25,25) 0.0313

>>
>> np=size(p,2);
nt=size(t,2);
M=zeros(ns,ns);
for k=1:nt
sommets=t(1:3,k)
x=p(1,sommets);
y=p(2,sommets);
area=polyarea(x,y);
MK=[2 1 1;1 2 1;1 1 2]/12*area;
M(sommets,sommets)=M(sommets,sommets)+MK;
end;

sommets =

1
2
5

sommets =

1
5
4

sommets =

2
3
6

sommets =

2
6
5
sommets =

4
5
8

sommets =

4
8
7

sommets =

5
6
9

sommets =

5
9
8

sommets =

10
11
1

sommets =

10
1
15

sommets =

11
12
2

sommets =

11
2
1

sommets =
12
13
3

sommets =

12
3
2

sommets =

13
14
18

sommets =

13
18
3

sommets =

15
1
4

sommets =

15
4
16

sommets =

16
4
7

sommets =

16
7
17

sommets =

3
18
19

sommets =

3
19
6

sommets =

6
19
20

sommets =

6
20
9

sommets =

17
7
22

sommets =

17
22
21

sommets =

7
8
23

sommets =

7
23
22

sommets =

8
9
24
sommets =

8
24
23

sommets =

9
20
25

sommets =

9
25
24

>> M

M =

Columns 1 through 12

0.0312 0.0052 0 0.0052 0.0052 0 0 0


0 0.0052 0.0052 0
0.0052 0.0312 0.0052 0 0.0052 0.0052 0 0
0 0 0.0052 0.0052
0 0.0052 0.0312 0 0 0.0052 0 0
0 0 0 0.0052
0.0052 0 0 0.0312 0.0052 0 0.0052 0.0052
0 0 0 0
0.0052 0.0052 0 0.0052 0.0312 0.0052 0 0.0052
0.0052 0 0 0
0 0.0052 0.0052 0 0.0052 0.0312 0 0
0.0052 0 0 0
0 0 0 0.0052 0 0 0.0312 0.0052
0 0 0 0
0 0 0 0.0052 0.0052 0 0.0052 0.0312
0.0052 0 0 0
0 0 0 0 0.0052 0.0052 0 0.0052
0.0521 0 0 0
0.0052 0 0 0 0 0 0 0
0 0.0104 0.0026 0
0.0052 0.0052 0 0 0 0 0 0
0 0.0026 0.0156 0.0026
0 0.0052 0.0052 0 0 0 0 0
0 0 0.0026 0.0156
0 0 0.0052 0 0 0 0 0
0 0 0 0.0026
0 0 0 0 0 0 0 0
0 0 0 0
0.0052 0 0 0.0052 0 0 0 0
0 0.0026 0 0
0 0 0 0.0052 0 0 0.0052 0
0 0 0 0
0 0 0 0 0 0 0.0052 0
0 0 0 0
0 0 0.0052 0 0 0 0 0
0 0 0 0
0 0 0.0052 0 0 0.0052 0 0
0 0 0 0
0 0 0 0 0 0.0052 0 0
0.0104 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0.0052 0
0 0 0 0
0 0 0 0 0 0 0.0052 0.0052
0 0 0 0
0 0 0 0 0 0 0 0.0052
0.0104 0 0 0
0 0 0 0 0 0 0 0
0.0156 0 0 0

Columns 13 through 24

0 0 0.0052 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0
0.0052 0 0 0 0 0.0052 0.0052 0
0 0 0 0
0 0 0.0052 0.0052 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0.0052 0.0052
0 0 0 0
0 0 0 0.0052 0.0052 0 0 0
0 0.0052 0.0052 0
0 0 0 0 0 0 0 0
0 0 0.0052 0.0052
0 0 0 0 0 0 0 0.0104
0 0 0 0.0104
0 0 0.0026 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0
0.0026 0 0 0 0 0 0 0
0 0 0 0
0.0156 0.0026 0 0 0 0.0052 0 0
0 0 0 0
0.0026 0.0052 0 0 0 0.0026 0 0
0 0 0 0
0 0 0.0156 0.0026 0 0 0 0
0 0 0 0
0 0 0.0026 0.0156 0.0026 0 0 0
0 0 0 0
0 0 0 0.0026 0.0156 0 0 0
0.0026 0.0052 0 0
0.0052 0.0026 0 0 0 0.0156 0.0026 0
0 0 0 0
0 0 0 0 0 0.0026 0.0156 0.0026
0 0 0 0
0 0 0 0 0 0 0.0026 0.0260
0 0 0 0
0 0 0 0 0.0026 0 0 0
0.0052 0.0026 0 0
0 0 0 0 0.0052 0 0 0
0.0026 0.0156 0.0026 0
0 0 0 0 0 0 0 0
0 0.0026 0.0156 0.0026
0 0 0 0 0 0 0 0
0 0 0.0026 0.0260
0 0 0 0 0 0 0 0.0078
0 0 0 0.0078

Column 25

0
0
0
0
0
0
0
0
0.0156
0
0
0
0
0
0
0
0
0
0
0.0078
0
0
0
0.0078
0.0313

>>