Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Alpha and beta extraction on an ellipse...

Asked by Chris E. on 21 Oct 2012

I have a program I am working on that uses the "Liouville's theorem" for an ellipse, similar to the first slide of the web page, " http://www-pnp.physics.ox.ac.uk/~delerue/accelerator_option/6_emittance.pdf ".

 I need to extract the alpha and beta.  

I have images that come in that have the ellipse on them, I extract the x and y projections to give x and x'. This is then used to produce the alpha and beta of the image for the ellipse.

So far I have a program that does this. I'm at the point I need to make it faster and decrease the time it takes to process.

I have two questions:

Does matlab have a prebuilt function that does this already (extract data from an ellipse or alpha and beta)? (that make life easier you know!)

If not, then how can I make this code below work faster... (this is a snip of code that seems to take a bit of time to solve when it has lots of data going through it):

ParNum = 3;

NumPoints = 26;

ery = 1.0e-014 *[ 0.2081 0.2125 0.2100 0.1962 0.2213 0.2027 0.1985 0.2048 0.168 0.1859 0.1607 0.1713 0.1502 0.1421 0.1383 0.1657 0.1435 0.1365 0.1342 0.1445 0.1354 0.1394 0.1248 0.1265 0.1315 0.1396];

y = 1.0e-005 *[0.3221 0.3266 0.3240 0.3097 0.3356 0.3165 0.3121 0.3187 0.2798 0.2988 0.2711 0.2829 0.2592 0.2497 0.2453 0.2767 0.2513 0.2432 0.2404 0.2526 0.2418 0.2466 0.2290 0.2312 0.2372 0.2468];

x = [-0.8327 -0.7981 -0.7636 -0.7290 -0.6944 -0.6598 -0.6252 -0.5906 -0.5560 -0.5214 -0.4868 -0.4522 -0.4177 -0.3831 -0.3485 -0.3139 -0.2793 -0.2447 -0.2101 -0.1755 -0.1409 -0.1063 -0.0718 -0.0372 -0.0026 0.0320];

for k=1:ParNum

    for i=1:NumPoints
        f(k)=power(x(i),k-1);
        beta_element(k,i)=y(i)*f(k)/(ery(i)*ery(i));
        beta(k)=sum(beta_element(k,:));
    end

end

for k=1:ParNum

    for l=1:ParNum
        for i=1:NumPoints
            f(k)=power(x(i),k-1);
            f(l)=power(x(i),l-1);
            alpha_element(k,l,i)=f(k)*f(l)/(ery(i)*ery(i));
            alpha(k,l)=sum(alpha_element(k,l,:));
        end
    end

end

Here is the output of alpha and beta...

K>> alpha

alpha =

1.0e+031 *
    1.0549   -0.3348    0.1687
   -0.3348    0.1687   -0.0997
    0.1687   -0.0997    0.0646

K>> beta

beta =

1.0e+025 *
    2.7766   -0.9531    0.5016

Any help or advice on this matter is much appreciated!

Thank you,

Chris

0 Comments

Chris E.

Products

1 Answer

Answer by Pedro Villena on 22 Oct 2012
Accepted answer
beta_element = zeros(ParNum,NumPoints);
beta_factor = y./(ery.^2);
alpha_element = zeros(ParNum,ParNum,NumPoints);
for k = 1:ParNum,
    f = x.^(k-1);
    beta_element(k,:) = beta_factor.*f;
    alpha_factor = f./(ery.^2);
    for l=1:ParNum,
        alpha_element(k,l,:) = alpha_factor.*x.^(l-1);
    end
end
beta = sum(beta_element,2)';
alpha = sum(alpha_element,3);

1 Comment

Chris E. on 22 Oct 2012

Thank you for the help! good way about it...

Pedro Villena

Contact us