plot Bethe-Bloch equation

Dear people,
For a project I have to plot the Bethe-Bloch equation. That is this equation: dedx = (-K*z^2*Z)/(A*beta2)*(0.5*log((2*me*1*10^9*beta2.*gamma2.*Tmax)/I^2)-beta2);
Every time i want to run the program it says the matrix dimension must agree. i do not know what i am doing wrong. I am trying this since the morning and I would like to move on. The only thing that chances is the eng. This has to run from 0 to 0.5 GeV.
clc; clear; z = 1; re = 2.817*10^-15; Z = 29; A = 63.546; Na = 6.022*10^23; mp = 0.93827231; %GeV eng = 0.001:0.001:0.5; %GeV gamma = (eng + mp)/mp; gamma2 = gamma.*gamma; beta = (1.0 - (1.0/(gamma2)')).^0.5; beta2 = beta.*beta; me = 0.51*10^-3; c = 3*10^8; I = 10*Z; K = 4*pi*Na*re^2*me*c^2;
Tmax = (2.0 * me*1e9*beta2'*gamma2)/(1.0 + (2.0*gamma*(me/mp) + (me/mp)^2)); Tmax = Tmax';
dedx = (-K*z^2*Z)/(A*beta2)*(0.5*log((2*me*1*10^9*beta2.*gamma2.*Tmax)/I^2)-beta2);
figure; plot(eng,dedx);

3 Commenti

Honglei Chen
Honglei Chen il 27 Feb 2012
Please format your code
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Jeroen
Jeroen il 27 Feb 2012
clc;
clear;
z = 1;
re = 2.817*10^-15;
Z = 29; A = 63.546;
Na = 6.022*10^23;
mp = 0.93827231; %GeV
eng = 0.001:0.001:0.5; %GeV
gamma = (eng + mp)/mp;
gamma2 = gamma.*gamma;
beta = (1.0 - (1.0/(gamma2)')).^0.5;
beta2 = beta.*beta;
me = 0.51*10^-3;
c = 3*10^8;
I = 10*Z;
K = 4*pi*Na*re^2*me*c^2;
Tmax = (2.0 * me*1e9*beta2'*gamma2)/(1.0 + (2.0*gamma*(me/mp) + (me/mp)^2));
Tmax = Tmax';
dedx = (-K*z^2*Z)/(A*beta2)*(0.5*log((2*me*1*10^9*beta2.*gamma2.*Tmax)/I^2)-beta2);
figure;
plot(eng,dedx);
Kunal Kumar
Kunal Kumar il 25 Mag 2021
Jeroen, I am having this same problem. Can you help me with the code. I tried running your code but it shows error. Can you share the code that ran on MATLAB.

Accedi per commentare.

Risposte (1)

Grzegorz Knor
Grzegorz Knor il 27 Feb 2012

0 voti

Use .* (the element-by-element product) operator for array multiplication.

3 Commenti

Jeroen
Jeroen il 27 Feb 2012
Okay thank you but that does not solve my problem. It keeps on saying that matrix dimensions must agree.
Grzegorz Knor
Grzegorz Knor il 27 Feb 2012
The same for division: ./
I've checked, and it works.
Jeroen
Jeroen il 27 Feb 2012
Okay thank you. It works now!

Accedi per commentare.

Categorie

Scopri di più su Mathematics in Centro assistenza e File Exchange

Richiesto:

il 27 Feb 2012

Commentato:

il 25 Mag 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by