I am trying to integrate in Matlab a function f(x) which consists of two functions g(x) and h(x) where g(x) is exact integrable and h(x) is integrable by numerical method .
To integrate a function f(x) which consists of two functions g(x) and h(x) where g(x) is exact integrable and h(x) is integrable by numerical method in MATLAB, you can use a combination of symbolic and numerical integration.
Here's an example:
Suppose we want to integrate the function f(x) given by:
```
f(x) = g(x) + h(x)
```
where g(x) is exact integrable and h(x) is integrable by numerical method.
1. Define the symbolic expression for g(x) using the `syms` function:
```
syms x
g(x) = sin(x);
```
2. Define a function handle for h(x) using the `@(x)` notation:
```
h = @(x) x.^2;
```
3. Integrate g(x) symbolically using the `int` function:
```
G = int(g(x), x);
```
4. Define the function f(x) as the sum of g(x) and h(x):
```
f = @(x) G + h(x);
```
5. Integrate f(x) numerically using the `integral` function:
```
a = 0; % lower limit of integration
b = pi/2; % upper limit of integration
Q = integral(f, a, b);
```
The variable `Q` will now contain the numerical value of the definite integral of f(x) from a to b.
Note that in this example, we used the `int` function to integrate g(x) symbolically because it is an exact integrable function. If g(x) were not exact integrable, you could use numerical integration to approximate its integral as well.