how to do it using matlab.
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (2)
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 Kommentare
Rizwana
am 7 Nov. 2013
Simon
am 7 Nov. 2013
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
am 8 Nov. 2013
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!