Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: PDF to CDF in MATLAB
Replies: 5   Last Post: Jan 14, 2013 4:59 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,893
Registered: 12/7/04
Re: PDF to CDF in MATLAB
Posted: Jan 13, 2013 3:55 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Monday, January 14, 2013 8:40:09 AM UTC+13, Hemming wrote:
> Hi!
>
> Im trying to extract a scattering angle for a photon using the Klein-Nishina scattering angle distribution (KN in the code) and for this I need the CDF (of KN) to be able to use the Monte Carlo method when that is achieved. All i've managed so far is to plot the PDF between 0 degrees and Pi to see that it looks alright, and that it has that "peanut shape". Ive tried to use the built in CDF function but it seems very slow.
>
>
>
> E_gamma=0.140;
>
> alpha=0.511;
>
> P=zeros(3142,1);
>
> KN_matrix=zeros(3142, 1);
>
>
>
> for k=1:3142
>
> j=(k-1)/1000;
>
> PE=1/(1+((E_gamma/alpha)*(1-cos(j))));
>
> KN=(PE^2*(PE+(1/PE)-1+(cos(j))^2))/2;
>
> KN_matrix(k,1)=(KN);
>
> plot(j,KN_matrix(k,1))
>
> hold on
>
> end
>
>
>
> Thanks!
>
> axis equal


Instead of plotting in a loop, define vectors:
j=[0:3141]'/1000;
PE=1/(1+((E_gamma/alpha)*(1-cos(j))));
KN_matrix=(PE.^2.*(PE+(1./PE)-1+(cos(j)).^2))/2;
plot(j,KN_matrix)

Notice the dots before the operators to get element-by-element multiplication, exponentiation, etc.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.