WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Matrix aufteilen

 

Paet0r
Forum-Anfänger

Forum-Anfänger


Beiträge: 30
Anmeldedatum: 13.08.10
Wohnort: Dresden
Version: ---
     Beitrag Verfasst am: 19.08.2010, 16:38     Titel: Matrix aufteilen
  Antworten mit Zitat      
Hallo, Leute =)
Habe folgendes Anliegen:
Ich muss für die Uni ein Programm schreiben, welches die Energiedichte berechnet. So eins habe ich nun. Es berechnet aus der zuvorhergeladenen Matrix die Energiedichte. (in der Matrix stehen die Teilchenpositionen in x und y Koordinaten sowie deren Impuls) Damit hab ich folgende Funktion:

Code:

function [D] = D(M)
% A function to get the Energiedichte

% The length of the Matrix we got through filechose
Lx=length(M);
% The minimum and maximum of the x and y koordinates:
Xmi=min(M(1:Lx,1));
Xma=max(M(1:Lx,1));
Ymi=min(M(1:Lx,2));
Yma=max(M(1:Lx,2));
% now we get the area, we are in, thorugh this one:
Flaeche = ((Xma-Xmi)*(Yma-Ymi));


% der folgende Teil ist nicht so wichtig

% Now we need the function for the Energy again:

% the vector x is a vector with all the data from all third collumns of your Matrix (gamma * beta x)
x = M(:,3);
% the vector x is a vector with all the data from all fourth collumns of your Matrix (gamma * beta y)
y = M(:,4);
% the vector x is a vector with all the data from all fivth collumns of your Matrix (gamma * beta z)
z = M(:,5);
% Getting the gamma for: Ekin=(gamma-1)*m0*c^2
gamma = sqrt((x.^2)+(y.^2)+(z.^2)+1);
% Speed of light(in M/s, SI)
global c = 2.99792458e+008
% Mass of a Proton(in kg, SI)
global mp = 1.6726231e-024
% Mass of an Electron(in kg, SI)
global me = 9.1093897e-031
% Mass of a Neutron(in kg, SI)
global mn = 1.6749286e-024
% Getting Ekin for: E=Ekin+Ecalm
Ekin = (((gamma-1).*mp).*(c^2));
% The whole Energy: Ekin + Ruheenergie
E = Ekin .+ (mp*(c^2));

% jeztt wirds wieder wichtig =)

Eg=sum(E);
D = (Eg/Flaeche);
 


Meine Frage ist nun:
Wie kann ich diese Funktion so verändern, sodass man abgesehen von der Matrix noch 2 Parameter angibt(am Anfang), die besagen, wie detailiert ich die Fläche unterteile, sodass ich die Energiedichte für einzelne Flächen berechnen kann, und diese alle in einem Array ausgegeben bekomme.
Bzw. als programmiererische Frage: Wie kann ich die Länge vom Minimalen bis Maximalen Y und X Koordinaten durch einen Parameter aufteilen, den man vorher angeben muss; z.B: D(M,1,1), so dass er in einer beispielsweise for-schleife die von X-bzw. Ymin bis max in einer-Schritten geht, und daraus die Teilflächen bestimmt.

Danke im Vorraus
Mfg
Paet0r
Private Nachricht senden Benutzer-Profile anzeigen


Paet0r
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 30
Anmeldedatum: 13.08.10
Wohnort: Dresden
Version: ---
     Beitrag Verfasst am: 23.08.2010, 15:43     Titel:
  Antworten mit Zitat      
Hab das Problem jetzt etwas anders gelöst.
Man kann die Energiedichte hiermit für jeden, duch den User bestimmten, Bereich berechnen:(sehr hilfreich evtl. Wink )



Code:

function [D] = D(M,Xmi,Xma,Ymi,Yma)
% Funktion zur Bestimmung der Energiedichte

A = [];
len=length(M);
for i = 1:len
 if M(i,1)>=Xmi &  M(i,1)<=Xma
  if M(i,2)>=Ymi & M(i,2)<=Yma
   A = [A;M(i,:)];
   end;
  end;
 end;
   % the vector x is a vector with all the data from all third collumns of your Matrix (gamma * beta x)
x = A(:,3);
% the vector x is a vector with all the data from all fourth collumns of your Matrix (gamma * beta y)
y = A(:,4);
% the vector x is a vector with all the data from all fivth collumns of your Matrix (gamma * beta z)
z = A(:,5);
% Getting the gamma for: Ekin=(gamma-1)*m0*c^2
gamma = sqrt((x.^2)+(y.^2)+(z.^2)+1);
% Speed of light(in M/s, SI)
global c = 2.99792458e+008
% Mass of a Proton(in kg, SI)
global mp = 1.6726231e-024
% Mass of an Electron(in kg, SI)
global me = 9.1093897e-031
% Mass of a Neutron(in kg, SI)
global mn = 1.6749286e-024
% Getting Ekin for: E=Ekin+Ecalm
Ekin = ((gamma-1).*(mp*(c^2)));
% The whole Energy:
E = Ekin.+(mp*(c^2));
% summing of all the Energy of each Proton
Eg = sum(E);
% getting the are we are currently in
Area = ((Xma-Xmi)*(Yma-Ymi));
% Getting the Dichte
D = (Eg/Area);
   
 end
 
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.