How To Plot a Function of Two Variables in MATLAB? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In order to plot a function of two variables in Matlab first you have to know some functions like plot, meshgrid() function, and very well know about how to plot one variable functions in Matlab. You have to follow some main contents or you can say procedure to plot a function. Below is the process to plot two variables function in Matlab: Algorithm: Define a grid of (x,y) points.Apply the function to the grid to get values of z.Use meshgrid() function.Plot the resulting mesh.Let's take an example to plot a two-variable function. Below is the plotting of the z= x^3 + y^3 function which is a two-variable function. Example 1: Matlab [x,y] = meshgrid(-4:1:4, -4:1:4); z = x.^3 + y.^3; mesh(x,y,z); Output: Explanation:first, we make a grid that is -4 to 4 with a distance of 1 in both the x and y axis and then we calculated the z value by our equation x^3+y^3. and then we use the mesh function to plot x,y and z. If you want to see the surface of the function then below is a surface diagram of the above function:- Example 2: Matlab x = linspace(-5,5); y = linspace(-5,5); [x,y] = meshgrid(x,y); z= x.^3 + y.^3; mesh(x,y,z); Output: Explanation: In the above example, we use linspace( x1,x2 ) function which will return a row vector of 100 evenly spaced points between x1 and x2 and then we calculated the z value which is x^3+y^3 at every point and then use mesh which plot in 3d surface. Comment More infoAdvertise with us Next Article How to Create a Scatterplot in R with Multiple Variables? K ksam24000 Follow Improve Article Tags : Software Engineering Technical Scripter 2022 MATLAB-programs Similar Reads How to create a function in MATLAB ? A function is a block of statements that intend to perform a specific task. Functions allow the users to reuse the code frequently. MATLAB has several predefined functions which are ready to use such as sin(), fact(), cos() etc. MATLAB also allows the users to define their own functions. Syntax: fun 2 min read How to Create a Scatterplot in R with Multiple Variables? In this article, we will be looking at the way to create a scatter plot with multiple variables in the R programming language. Â Using Plot() And Points() Function In Base R: In this approach to create a scatter plot with multiple variables, the user needs to call the plot() function Plot() function: 3 min read Private Functions in MATLAB Private functions are useful when you want to limit the scope of a function. Here we will learn how to create private functions and also use them. Private functions are primary functions that are visible only to a limited group of other functions. Generally, we make private functions, if we want to 2 min read Function With Variable Number of Input Arguments in MATLAB MATLAB functions have the functionality that many other programming languages lack. A MATLAB function can take a variable number of input arguments, without the use of arrays or any additional functionality. The way to go about this in MATLAB is by using the varargin - which can be interpreted as VA 2 min read How to plot user-defined functions in R? Plotting user-defined functions in R is a common task for visualizing mathematical functions, statistical models, or custom data transformations. This article provides a comprehensive guide on how to plot user-defined functions in R, including creating simple plots, enhancing them with additional fe 3 min read Plot Expression or Function in MATLAB In this article, we will discuss how to plot expressions or functions in MATLAB. We can make use fplot() function in MATLAB to generate the plot corresponding to an expression or function. There are different variants of fplot() function fplot(f)fplot(f,xinterval)fplot(___,LineSpec)fplot(___,Name,Va 3 min read Like