Azzera filtri
Azzera filtri

how to do it using matlab.

1 visualizzazione (ultimi 30 giorni)
Rizwana
Rizwana il 7 Nov 2013
Commentato: Rizwana il 8 Nov 2013
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

Risposta accettata

ES
ES il 7 Nov 2013
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 Commento
Rizwana
Rizwana il 8 Nov 2013
Iam thankfull and greatfull for your generous help. Thank you once again :)

Accedi per commentare.

Più risposte (2)

ES
ES il 7 Nov 2013
doesn't trapz(A) solve your case?
  2 Commenti
Rizwana
Rizwana il 7 Nov 2013
f(x) or A is some data. Not a function
ES
ES il 7 Nov 2013
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

Accedi per commentare.


Simon
Simon il 7 Nov 2013
Modificato: Simon il 7 Nov 2013
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 Commenti
Simon
Simon il 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
Rizwana il 8 Nov 2013
Thank You.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by