필터 지우기
필터 지우기

how to do it using matlab.

조회 수: 1 (최근 30일)
Rizwana
Rizwana 2013년 11월 7일
댓글: Rizwana 2013년 11월 8일
I have been asked to area averaging using scientific formula. The formula looks like this
Let A = integral between limits[a b] [ f(x).dx ]
My formula is
B = 1/b *(A);
My main problem is f(x) is just set of data and hence not an equation. If it was simple/complicated equation I would have solved it. But since its data of time along x-axis & pressure along y-axis
pressure 916.3 923.6 933.1 947.4 966.2 986.6 1008.5 1031.5 1051.3
time 1 2 3 4 5 6 7 8 9
So I applied trapezoidal rule.. tried coding it. Got it for h=4(or integer) but h changes to some non integer value its throwing error. h=(b-a)/n, eg :n= 4, h = 1.3 Hence A1(2.3). Matlab doesn’t work with these kind of indices.. I want to read A1(23) when it means 2.3. Anyone can give me some help… //just tried
t = 1:9;
t1 = 1 : 0.1 :9;
A = [916.3, 923.6, 933.1, 947.4, 966.2, 986.6, 1008.5, 1031.5, 1051.3];
A1 = interp1(t ,A , t1) ;
a= 1;
b=9;
h= 1.3;
for i = 0:3
res = 0.5*[A1(a+ i*h)+ A1(a + (i+1)*h)]*h
disp(res)
end

채택된 답변

ES
ES 2013년 11월 7일
I think I understand your question. trapz is a numerical integration method to which you supply a set of discontinued numbers. trapz will form trapezoids by interpolation, find the area under the curve. Look here<http://www.mathworks.in/help/matlab/ref/trapz.html>
  댓글 수: 1
Rizwana
Rizwana 2013년 11월 8일
Iam thankfull and greatfull for your generous help. Thank you once again :)

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

추가 답변 (2개)

ES
ES 2013년 11월 7일
doesn't trapz(A) solve your case?
  댓글 수: 2
Rizwana
Rizwana 2013년 11월 7일
f(x) or A is some data. Not a function
ES
ES 2013년 11월 7일
I think I understand your question. trapz is a numerical integration method to which you supply a set of discontinued numbers. trapz will form trapezoids by interpolation, find the area under the curve. Look here

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


Simon
Simon 2013년 11월 7일
편집: Simon 2013년 11월 7일
Hi!
Trapeziod rule means you add both values on the right and left of your discretisation, multiply with the distance and take half of it. The integral is the sum over all such areas:
Integral = sum(((A1(1:end-1) + A1(2:end)) * 0.1) / 2);
  댓글 수: 3
Simon
Simon 2013년 11월 7일
You can write it as a loop like
% start at 0
Integral = 0;
% loop over all values (except the last one)
for n = 1:length(A1)-1
% values on both sides
leftvalue = A1(n);
rightvalue = A1(n+1);
% trapezoid area (0.1 is your t1 discretisation)
area = ((leftvalue+rightvalue) * 0.1) / 2;
% sum up whole area
Integral = Integral + area;
end
I think in your question you mix the "index" into the A1 array and the "position" in t1. If you need a position in t1, lets say 1.3, you can do
ind = find(t1 == 1.3);
This is the index in t1 and the index in A1, so the value at t=1.3 is in
ind = find(t1 == 1.3);
A1(ind)
Rizwana
Rizwana 2013년 11월 8일
Thank You.

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

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by