Any idea on how to create a n by n square matrix.
Afficher commentaires plus anciens
The size of the matrix follows the npanels=3
Let say for this case it is a 3 by 3 square matrix but if i want to create a 7 by 7 square matrix or a 15 by 15 square matrix I will have to repeat the procedure many times. I want MATLAB to be able to auto create a n by n square matrix by only changing the value of npanels.
Vector P,Vector x and Vector y are row vectors with 3 elements which is the value of npanels=3.
npanels=3; %number of panels
dP=2.4/npanels; %equal length panels
P=[-1.2+(2.4/npanels)/2:dP:1.2-(2.4/npanels)/2]; %panels x-ccordinates
a=1.25; %major axis
b=0.75; %minor axis
O=[pi-pi/(2*npanels):-pi/(npanels):pi/(2*npanels)]; %boundary points
r=(a*b)./sqrt((b*cos(O)).^2+(a*sin(O)).^2); % ellipse in polar coordinates
x=r.*cos(O); %x-coordinate
y=r.*sin(O); %y-coordinate
C1j=(y(1).*dP)./((x(1)-P).^2+(y(1).^2));
C2j=(y(2).*dP)./((x(2)-P).^2+(y(2).^2));
C3j=(y(3).*dP)./((x(3)-P).^2+(y(3).^2));
C=[C1j;C2j;C3j]
Réponse acceptée
Plus de réponses (2)
Andrew Newell
le 9 Mai 2011
Use meshgrid:
npanels=3; %number of panels
dP=2.4/npanels; %equal length panels
P=[-1.2+(2.4/npanels)/2:dP:1.2-(2.4/npanels)/2]; %panels x-ccordinates
a=1.25; %major axis
b=0.75; %minor axis
O=[pi-pi/(2*npanels):-pi/(npanels):pi/(2*npanels)]; %boundary points
[P,O] = meshgrid(P,O);
r=(a*b)./sqrt((b*cos(O)).^2+(a*sin(O)).^2); % ellipse in polar coordinates
x=r.*cos(O); %x-coordinate
y=r.*sin(O); %y-coordinate
C = y*dP./((x-P).^2 + y.^2)
1 commentaire
Paulo Silva
le 9 Mai 2011
good code +1 vote
Yoon Hong Ng
le 9 Mai 2011
1 vote
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!