- Sample the function at various points.
- Compute the zeroth-order term, which is the mean value of the function over the domain.
- Compute the first-order terms, which are the effects of each variable individually.
- Compute the second-order term, which is the interaction effect between the variables.
- Use Lagrange interpolation to approximate the function values.

# How do I use Cut-HDMR in MATLAB?

6 views (last 30 days)

Show older comments

Hi, I wish to use Cut-HDMR (HDMR = High Dimensional Model Representaion) to solve multivariate piecewise continuous functions. I found a code at https://in.mathworks.com/matlabcentral/fileexchange/92890-bivariate-cut-hdmr but could not understand their application.

Could someone please help me out with a sample code for a bivariate piecewise continuous function so that I can understand the process application in MATLAB? The expansion may be taken only upto the second order term with Lagrange interpolation.

Thanks

##### 0 Comments

### Answers (1)

Naren
on 17 Jan 2024

Edited: Naren
on 17 Jan 2024

Hello Rohit,

Inorder to apply bivariate CUT-HDMR (High Dimensional Model Representation) to a piecewise continuous function, follow the steps given below:

Given that you've mentioned using Lagrange interpolation and limiting the expansion to second-order terms, let's consider a simple bivariate piecewise continuous function as an example:

function z = piecewise_function(x, y)

if x < 0.5

if y < 0.5

z = sin(x) + cos(y);

else

z = cos(x) + sin(y);

end

else

if y < 0.5

z = x^2 + y^2;

else

z = x*y;

end

end

end

To apply CUT-HDMR to this function, we need to create a script that will perform the following steps:

Here's a simple MATLAB script that demonstrates these steps:

% Define the domain for the variables x and y

x_domain = linspace(0, 1, 10); % 10 points between 0 and 1

y_domain = linspace(0, 1, 10);

% Sample the function at the points in the domain

[X, Y] = meshgrid(x_domain, y_domain);

Z = arrayfun(@piecewise_function, X, Y);

% Compute the zeroth-order term (mean of the function)

h0 = mean(Z, 'all');

% Compute the first-order terms

hx = mean(Z, 2) - h0; % Mean over y, for each x

hy = mean(Z, 1) - h0; % Mean over x, for each y

% Compute the second-order term

hxy = Z - (h0 + hx + hy');

% Perform Lagrange interpolation for the first-order terms

% Note: For simplicity, we are doing interpolation at the sampled points

% In practice, you would use interpolation to estimate values at new points

hx_interp = interp1(x_domain, hx, x_domain, 'linear', 'extrap');

hy_interp = interp1(y_domain, hy, y_domain, 'linear', 'extrap');

% The CUT-HDMR approximation of the function is then:

Z_approx = h0 + hx_interp + hy_interp' + hxy;

figure;

subplot(1, 2, 1);

surf(X, Y, Z);

title('Original Function');

xlabel('x');

ylabel('y');

zlabel('z');

subplot(1, 2, 2);

surf(X, Y, Z_approx);

title('CUT-HDMR Approximation');

xlabel('x');

ylabel('y');

zlabel('z_approx');

Note that this is a simplified example. In practice, you would need to consider the continuity of the function and the appropriate interpolation method to apply. Also, the CUT-HDMR method can be more complex, especially for higher-dimensional functions and higher-order expansions.

Regards,

Naren

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!