specify domain of a function
Show older comments
When I define a function, how do I specify the domain, i.e. the values for which it is defined?
I am examining the behavior of a function that I can only express numerically. In other words, if the function is z=fun(x,y), then I can find the value of z for any x and y, but I cannot express it in closed form, i.e. in terms of algebraic or trigonometric expressions.
Important: x and y must be between -1 and 1, so fun is a mapping from [-1,1]x[-1,1]->R, where square brackets indicate the closed interval.
One thing I did was to define a grid of x and y values and create an NxN matrix of z values. In addition, I have vectors for x and y that map the indices of the matrix to the values between -1 and 1. Then, I can find the minimum, maximum, and gradient. I don't know of any way to tell the built-in MATLAB function gradient what the domain is, but it seems to be doing OK.
The I tried to use hessian from the derivest package (Adaptive Robust Numerical Differentiation) derivest The problem is that derivest/hessian does not know where the boundary of the domain is, so when it calculates a derivative, in goes out of bounds of the matrix (function).
At the moment, my problem occurs when I use derives to calculate the hessian numerically, but this appears to me like a very general question in MATLAB: How to specify the domain of a function.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!