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));
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.
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. )
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);
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
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.