MATLAB Numerical integration in matlab

AI Thread Summary
The discussion focuses on calculating arc length in MATLAB using a specific equation involving integration. The user seeks guidance on how to implement this calculation for varying values of parameters d and k. Suggestions include using MATLAB's trapz function for numerical integration and addressing issues with matrix dimension errors in their code. The user also describes their approach to iterating through parameter values to compute arc lengths, although it is noted that this method may be computationally intensive. Overall, the thread emphasizes the feasibility of performing the integration in MATLAB while highlighting potential coding challenges.
avaquake
Messages
2
Reaction score
0
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.
 
Physics news on Phys.org
avaquake said:
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.

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
 
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).
 
Brute force

Code:
>> 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:
>> surf(d,k,area)
Should work.
 

Similar threads

Replies
5
Views
3K
Replies
8
Views
2K
Replies
10
Views
3K
Replies
4
Views
1K
Replies
1
Views
2K
Replies
4
Views
4K
Replies
10
Views
3K
Back
Top