Matrix construction over a loop
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    ASHA RANI
 el 11 de Abr. de 2021
  
    
    
    
    
    Comentada: ASHA RANI
 el 12 de Abr. de 2021
            x=[1:1:10];
a=2;
b=4;
c=6;
for i=1:length(x)
A=a*b/x(i);
B=c+A(i)/b;
D=a+b;
E=1-2*c;
MAT=[B(i);D;E];
M=sqrt([MAT])
end
I am not able to matrix corresponding to 10 values of x.
plz help
thanks
1 comentario
  David Fletcher
      
 el 11 de Abr. de 2021
				This line will create a scaler value for A
A=a*b/x(i);
On the following line you are trying to index a scaler value
B=c+A(i)/b;
Respuesta aceptada
  VBBV
      
      
 el 11 de Abr. de 2021
        clear
x=[1:1:10];
a=2;
b=4;
c=6;
for i=1:length(x)
A(i)=a*b/x(i);
B(i)=c+A(i)/b;
D=a+b;
E=1-2*c;
MAT(i,:)=[B(i);D;E];
end
M=sqrt(abs(MAT))
2 comentarios
  VBBV
      
      
 el 11 de Abr. de 2021
				In my solution, the Matrix MAT is not  3 x 1. It is 10 x 3 for which sqrt is possible and same as what you would get if you perform MAT.^(1/2)  element wise operation.
Más respuestas (1)
  Jan
      
      
 el 11 de Abr. de 2021
        Maybe you want:
for i = 1:length(x)
  A(i) = a * b / x(i);
  B(i) = c + A(i) / b;
  D(i) = a + b;
  E(i) = 1 - 2 * c;
  ...
0 comentarios
Ver también
Categorías
				Más información sobre Loops and Conditional Statements 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!



