Can someonse show me how to calculate the following in matlab:
where
g = 9.91
As = 1000
z = 10
zv = 30
zD = 10
pz = 999
Az = 500
Well, there are a couple of ways to go about this:
Like Rudy commented, this is a trivial integral to do analytically because it's the integral of a power (z1). Its indefinite integral would be:
F(z) = (g/As)(z2/2 - zvz)pzAz
According to the Second Fundamental Theorem of Calculus, the definite integral is computed by substituting the integral bounds into F(z)
, that is:
ST = F(zd) - F(0) = (g/As)(zD2/2 - zvzD)pzAz
In MATLAB, that would be:
ST = g / As * zD * (zD / 2 - zv) * pz * Az
ST =
-1.2375e+06
If, for some reason, you want to calculate that numerically by approximating the integral, you can use the trapz
function for this:
dz = 0.001; z = 0:dz:zD;
y = g / As * (z - zv) * pz * Az;
ST = trapz(z, y)
ST =
-1.2375e+06
or make an even cruder approximation with a simple sum:
ST = sum(y * dz)
ST =
-1.2387e+06