フィルターのクリア

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 Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by