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

Honglei Chen
Honglei Chen 2012년 2월 27일
Please format your code
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Jeroen
Jeroen 2012년 2월 27일
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 2021년 5월 25일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Grzegorz Knor
Grzegorz Knor 2012년 2월 27일

0 개 추천

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

댓글 수: 3

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2012년 2월 27일

댓글:

2021년 5월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by