Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Numerical integration in matlab

  1. May 6, 2010 #1
    i am very new in matlab. and i need to calculate the arc lengh. My equation is
    arc length = integration of sqrt(d.*(k.^2-2).*sin(k.*t./2).^2 - d.*(k.^2-1).*sin(k.*t./2).^4 + 1); from 0 to 2.pi
    where, d=(0:.1:1) and k=(0:1:10)

    can anybody tell me whether it is possible to calculate this arc length using matlab. If possible can you suggest me the coding to write the script?

    thanks.
     
  2. jcsd
  3. May 7, 2010 #2

    MATLABdude

    User Avatar
    Science Advisor

    Welcome to PhysicsForums!

    First off, are you integrating over k, or over t? Do you just want arclengths for different values of k?

    Secondly, there are two ways of doing this: trapezoid rule, or with Simpson's rule.

    Given a vector of x, and an array of y, you can use MATLAB's trapz function:
    http://www.mathworks.com/access/helpdesk/help/techdoc/ref/trapz.html

    With a function handle (see inside the documentation page for a link--think of it as an inline function), you can use the MATLAB quad function:
    http://www.mathworks.com/access/helpdesk/help/techdoc/ref/quad.html
     
  4. May 9, 2010 #3
    i am integrating with repest to t. and yes i want arclength for different values of k as well as d.
    for example: when d=.1, k=1:1:10, this will give me 10 different value of arclength.
    when d=.2, k=1:1:10, this will again give me another 10 differenct value of arclength.
    ......................
    ......................
    until d=1.

    i have tried with the following to apply Z = trapz(X,Y).
    >> x= 0:2*pi/100:2*pi;
    >> k=(1:.1:10);
    >> y=sqrt(1+0.1.*(k.^2-2).*sin(k.*x./2).^2-0.1.*(k.^2-1).*sin(k.*x./2).^4);
    but this line give me an error msg.
    ??? Error using ==> times
    Matrix dimensions must agree.

    another problem is that i have fixed the value of d=.1 , as i do not know how to set the value of two variables at a time so that it gives me the results of arclength as my requirement(as i give an example in the beginning).
     
  5. May 10, 2010 #4
    Brute force

    Code (Text):

    >> d = 0:0.1:1;
    >> k = 0:1:10;
    >> t = 0:0.01:2*pi;
    >> size(t)
    ans =
         1   629


    >> for i = 1:11
    >> for j = 1:11
    >> for l = 1:629
    >> f(i,j,l) = sqrt(d(i)*(k(j)^2-2)*sin(k(j)*t(l)/2)^2 - d(i)*(k(j)^2-1)*sin(k(j)*t(l)/2)^4 + 1);
    >> 100*i*j*l/(629*11*11)
    >> end
    >> end
    >> end
    >> area = sum(f*0.01,3);
    For each parameter configuration (there are 121 in your post = 11*11) this calculates the height of the curve you gave, from 0 to 2*pi in intervals of 0.01 (629 total calculations).

    It then approximates the curve as a step function, or 629 different rectangles, and will therefore overestimate the area if the gradient is negative and underestimate the area if it is positive. It's a decent and simple first approximation.

    Word of warning, this takes a long time.

    area is an 11x11 double of your areas in parameter space. To see how it varies graphically,
    Code (Text):
    >> surf(d,k,area)
    Should work.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Numerical integration in matlab
Loading...