Ex4-5: Mesh and plot a surface
My Solutions:
Write a function named ex4p5. It receives two vector variables and returns three matrices.
Write a subfunction that implements the "three-hump camel" function:
f(x, y) = 2x^2 - 1.05x^4 + (x^6)/6 + xy + y^2
Write your subfunction in such a way that it accepts "vectorized" input (i.e. it computes function values elementwise when x and y values).
Your main function receives two variables which contain the ranges of x and y, i.e. [xmin, xmax] and [ymin, ymax].
Your main function returns as output values three 10x10 matrices, which contain the x, y coordinate combinations (use the "meshgrid" function, two first values) and the corresponding z = f(x, y) values (as the third function value).
Draw the function surface using the function "surf". Give your figure a title and label the axes. Note that the Moodle interface does not display figures - use Matlab to see what you've drawn. (To see the "humps" you need more points than ten points in each direction and probably also a logarithmic z-axis.)
(Food for thought - do not return: How you could change your function so that if one of the coordinate ranges would be just a scalar, it would draw a 2D line? Or if both coordinate ranges were scalars, function would return just the function value with the given pair of coordinates?)