Skip to main content

Software Example - MATLAB

 In this example I will be showing you how you can do 3-D plotting in MATLAB, lets start:


Three-dimensional plots typically display a surface defined by a function in two variables, z = f(x,y) .

To evaluate z, first create a set of (x,y) points over the domain of the function using meshgrid.

Write the following code :

[X,Y] = meshgrid(-2:.2:2);

Z = X .* exp(-X.^2 - Y.^2);

Then create a surface plot, using this code:

surf(X,Y,Z)

The code should look this:


Both the surf function and its companion mesh display surfaces in three dimensions. surf displays both the connecting lines and the faces of the surface in color. mesh produces wireframe surfaces that color only the lines connecting the defining points.



Press the "RUN" button highlighted in the top panel of the software to display the 3-D Plotted figure, and the final result should look like this:



You can display multiple plots in different subregions of the same window using the subplot function.

The first two inputs to subplot indicate the number of plots in each row and column. The third input specifies which plot is active. For example, create four plots in a 2-by-2 grid within a figure window.

Use the following code: 

t = 0:pi/10:2*pi;

[X,Y,Z] = cylinder(4*cos(t));

subplot(2,2,1); mesh(X); title('X');

subplot(2,2,2); mesh(Y); title('Y');

subplot(2,2,3); mesh(Z); title('Z');

subplot(2,2,4); mesh(X,Y,Z); title('X,Y,Z');

To see the following result:



P.S: Screenshots are taken by the author.






Comments

Popular posts from this blog

Neural Network (Initial Idea 2)

Neural Networks   Neural Networks, colloquially known as artificial neural networks (ANNs) and also simulated neural networks (SNNs), are a sub-fiend of machine learning which in it self is a sub-field of Artificial Intelligence, they are the brain of AI and are components of deep learning. The name and structure of NNs are similar to the human brain and were inspired by it, they imitate the biological neurons by signaling to each other (IBM, 2020). ANNs consist of an input layer of neurons, one or two hidden layers of neurons and a final layer of output neurons (Wang, 2003).   The diagram illustrated exemplifies a simple architecture of a neural network, the lines which connect the neurons are called weights and are associated with a number which represent the strength of connection between neurons.   There are many different types of neural networks and each are used for specific motives. Below are some of the most common ones used in the field: The perceptron “the oldest neur