0

My task is to calculate the area between two curves (named 'water retention curves'). I tried to calculate this area with the build-in 'integral' function (see line 32), but the command window tells me the output of the function must be of the same length as the input of the function. As you can see, I define my functions as function handles (which is asked). I'm new to this method, so I expect my mistake to be in the definition of my function handles.

t_r = 0.045;
t_s = 0.43;
alfa = 0.145;
n =2.68;

z=-200:1:0;

% Calculate theta_150 and theta_200 with waterretentioncurve
% function (see below) depending on h_150 and h_200 (which both
% depend on z): 

grondw_200 = -200;
h_200 = grondw_200 - z; 
theta_200 = @(h_200) waterretentioncurve(t_r,t_s,alfa,n,h_200);

grondw_150 = -150;
h_150 = grondw_150 - z;
theta_150 = @(h_150) waterretentioncurve(t_r,t_s,alfa,n,h_150);

% Calculate the area between these functions. We substract the lower
% function from the upper function, which gives a function
% deltatheta_200_150 and is easy to integrate. 
% Calculate deltatheta200_150 = theta_150 - theta_200 (with
% input variables depending on h_200 and h_150 (depending on z)):

deltatheta_200_150= @(h_150,h_200) theta_150(h_150) - theta_200(h_200);

% Problem calculating the integral of function deltatheta_200_150. The
% command window tells me the function output must be the same size as 
% the function input. How do I solve this issue? 

deltastorage_200_150 = integral(@(deltatheta_200_150) theta_150(h_150_sand) - theta_200(h_200),-200,0)

function th = waterretentioncurve(th_r,th_s,alfa,n,h)
h(h>0)=0;
    th = th_r + (th_s-th_r)./(1+(alfa.*abs(h)).^n).^(1-1/n);
end

Thanks in advance!

I tried to adjust the definition of my function handles in the integral-function, but this made the output in the command window look worse :)

Haïko
  • 11
  • 1
  • The thing inside the `@(x)` is the input of that anonymous function. You're not quite using anonymous functions correctly, because you appear to be specifying these variables before the function definition in each case - but that will have no impact. If you're unsure how to use anonymous functions properly then it's probably easier to see what's going on by just writing them as [local functions](https://uk.mathworks.com/help/matlab/matlab_prog/local-functions.html) e.g. `function dt = theta( x )`, then use as a function handle for `integral` by referencing as `@theta` – Wolfie Oct 28 '22 at 11:15

0 Answers0