evaluate two variable symbolic expression for every combination of values between 10 and -10 in matlab and then make a surface plot in matlab

To evaluate a two variable symbolic expression for every combination of values between 10 and -10, we can use the meshgrid function to create a grid of points, and then evaluate the expression at each point. We can also use the surf function to create a surface plot of the evaluated expression.

Here's an example code:

main.m
syms x y;
f = x^2 + y^2; % symbolic expression
x_vals = linspace(-10, 10, 100); % values between -10 and 10
y_vals = linspace(-10, 10, 100);
[X,Y] = meshgrid(x_vals, y_vals); % create a grid of points
Z = subs(f, [x, y], {X, Y}); % evaluate the expression at each point
surf(X, Y, Z); % create the surface plot
xlabel('x');
ylabel('y');
zlabel('z');
350 chars
11 lines

In this example, the linspace function is used to generate 100 equally spaced points between -10 and 10 for both x and y variables. The meshgrid function is used to create a grid of points, X and Y, for every combination of x_vals and y_vals. Then we use the subs function to evaluate the symbolic expression f at each point in the grid. Finally, the surf function is used to create the surface plot of the evaluated expression Z.

gistlibby LogSnag