Visualizing a Function of Two Variables
Learn the ins and outs of creating useful visualizations of functions that feature two variables. Follow a demonstration of the key benefits of the fplot function and how you can use it to create your data visualizations. More advanced versions of fplot are also covered, as well as similar functions such as fplot3 and fimplicit.
For further learning on modifying the output of fplot depending on the input arguments, check out these documentation pages diving into fplot, FunctionLine, and ParameterizedFunctionLine characteristics:
Published: 1 Jul 2022
Hello, and welcome back to another MATLAB video. Today, we're talking about visualizing a function of two variables in MATLAB. Anyone who needs to wrangle more than one set of data when attempting to plot knows this is a vital skill for creating effective visualizations. A function of two variables shows the relationship between those two variables. And visualizing it using the family of function plots makes plain any notable patterns in that relationship.
To create this visualization, fplot makes it easy. Using fplot draws the curve defined by the equation y equals f of x over the default interval negative 5 to 5 for x. If you want to adjust the x-interval, use fplot of f comma x-interval to plot over the specified interval tmin in to tmax. Fplot can be for established functions like y equals sine of x or y equals cosine of x shown here, as well as ones you build yourself like this piecewise function shown here.
Beyond the standard fplot, there are multiple uses for fplot that you can take advantage of to plot whatever you may need. fplot of function x function y and, optionally, t-interval plots two functions-- each of two variables-- with both functions sharing the variable t.
This is distinct from the hold on command since these two functions are linked by a variable and graphed at the same time, as opposed to simply being overlaid on the same plot as shown here. There are also other members of the function plot family worth exploring for their various functionalities. These include fimplicit, which allows you to plot an implicit function of two variables like x squared plus y squared plus 1 equals 0, as well as others, including fplot 3, fcontour, and fmesh.
Do you want to change the appearance of your fplot function? Check out the documentation for more information on visualization aesthetic adjustments. In this video, we have covered the important aspects of the fplot function in MATLAB, which allows you to visualize the function of two variables. Now that we have a better understanding of how to create graphics objects which relate two variables, you can be more confident and effective in your ability to point out important trends and patterns in your data. Thanks for watching, and I'll see you guys in another video.