1

i'm looking for to solve a definite integral of two vectors, I try to explain.

I know: z vector of numbers and G(z) vector of numbers.

The limits of integration are zmin and zmax

I should to calculate: Integral between zmin,zmax of [G(z) * z^(7/6)] dz

Could I solve with the following code?

For i = zmin:zmax
myresult = G(z(i))*z(i)^(7/6)
end
Mixo
  • 191
  • 13

1 Answers1

0

(wrote before)

You can use numerical integral.

Define G(z) as a function handle, and the function to be integrated as another one. You can find an example in my other answer.


So your goal is to calculate the sum of [G(z) * z^(7/6)] * dz, where G(z) and z are pre-calculated numerical vectors, dz a small increment value.

dz = (zmax - zmin) / length(G(z));
S = G * z' * dz;

S should be the result. Let me explain.

  • First of all, I messed up with G(z) previously (apologize for that). You have already evaluated (partially) the function to integrate, namely G(z) and z.
  • G(z) and z are number arrays. Arrays are indexed by integer, starting from 1. So G(z(i)) may not be a valid expression, as z(i) haven't been guaranteed to be integers. The code above only works correctly if you have defined G(z) in this way - G(i) = some_function (z(i));. By so each element of the same index in two arrays have a meaningful relation.
  • There are several ways to evaluate the product of two arrays (vectors), generating a single-value sum. A for loop works, but is inefficient. G * z' is the way to calc vector dot product.
Community
  • 1
  • 1
Yvon
  • 2,903
  • 1
  • 14
  • 36
  • Thank Yvon, but I did not understand how to define G(z). I tried the following code: fun = @(z) g(z).*z.^(7/6); q = integral(fun,z(1),z(end-1)); but I receive "Undefined function 'g' for input arguments of type 'double'" – Mixo Jul 16 '14 at 14:48
  • 2 things to note - Do you have a clear definition of G(z)? Post here so maybe I can help you build a function handle. Also, you don't need z(1) and z(end-1) in `integral`, they are just two numbers, not a complicated function (or are they?) – Yvon Jul 17 '14 at 01:27
  • G(z) is a vector of double as Z and they have the same length – Mixo Jul 17 '14 at 09:12
  • Sorry I didn't realize that. This then leads to a different answer. – Yvon Jul 17 '14 at 14:04
  • @Mixo Is it possible to show the entire problem? It seems you are defining `z` as integers in the problem, but usually an integral does not pick up integers only. – Yvon Jul 17 '14 at 14:29