Matlab - Vectorizar Matrices

 
Vista:
Imágen de perfil de Alex

Vectorizar Matrices

Publicado por Alex (1 intervención) el 11/06/2016 00:29:01
DESEO VECTORIZAR ESTA MATRIZ YA QUE CUANDO DOY EL VALOR DE n GRANDE LA SENTENCIA FOR SE DEMORA MUCHO

1
2
3
4
5
6
7
8
9
10
11
12
13
B=zeros(n-1,3)
for i=1:n-1
    for j=1:3
        if ((i==1) && (j==1))||((i==n) && (j==3))
            B(i,j)=0;
        end
        if (i>= 2)
            B(i,1)= -p1(xjt(i))/h^2;
            B(i,3)=-p1(xjt(i+1))/h^2;
        end
        B(i,2)= (p1(xjt(i))+p1(xjt(i+1)))/h^2 + q1(x(i+1));
    end
end
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Vectorizar Matrices

Publicado por Miguel (42 intervenciones) el 28/06/2016 21:00:05
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
B=zeros(n-1,3)
 
for i=1:n-1
 
    for j=1:3
 
         if  i*j == 1  ||   i*j == 3*n
        %if ((i==1) && (j==1))||((i==n) && (j==3))
 
            B(i,j)=0;
 
        end
 
        if (i > 1)
 
            B(i,1)= -p1(xjt(i))/h^2;
 
            B(i,3)=-p1(xjt(i+1))/h^2;
 
        end
 
        B(i,2)= (p1(xjt(i))+p1(xjt(i+1)))/h^2 + q1(x(i+1));
 
    end
 
end
 
 
% Prueba esto  quizas sea un poco más rápido
 
% Saludos
% comentanos como te fué
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar