Submit plots for parts (a) and (b) above and the M-code that produced them.Find and replace all complex entries with NaN's, then replot the function `y=sqrt(9-x^2)`.
Use writng to explain any mysterious horizontal segments in your plot. Use Matlab's plot command (with no adjustments) to draw the graph of `y=sqrt(9-x^2)` on the interval ``.After executing a cell, examine the contents of your folder and note that a PNG file was generated by executing the cell. There are options for executing both single and multiple cells.
#MATLAB 2018B ENABLE CELL MODE CODE#
After that, use the entries on the Cell Menu or the icons on the toolbar to execute the code in the cells provided in the file. The file complex.m is designed to be run in "cell mode." Open the file complex.m in the Matlab editor, then enable cell mode from the Cell Menu.
#MATLAB 2018B ENABLE CELL MODE DOWNLOAD#
Download the file to a directory or folder on your system. You can download the Matlab file at the following link.
Matlab FilesĪlthough the following file features advanced use of Matlab, we include it here for those interested in discovering how we generated the images for this activity. You can try to eliminate this behavior by increasing the number of points in the mesh, but in upcoming activities we'll demonstrate how a change of coordinates is a better solution. Replacing complex entries in z witn NaN's.Īs we saw in Example 1, we have some erratic behavior on the boundary (`x^2+y^2=4`) of the hemisphere. The following command should work on all systems. Users must have complained, because later versions of Matlab 7 have returned to the days of Matlab 6 and the mesh command will not work if entries have data that is complex.īy taking the real part of `z`, complex numbers are avoided. Then, in the early development of Matlab 7, an adjustment was made to Matlab's mesh command to allow it to work with complex data specifically, an adjustment in the code allowed it to deal with complex data in the same way as the the plot command dealt with complex data: it plotted the real part of any complex data entry. During the development stages of version 6, Matlab's mesh command would fail if it detected complex numbers in the data. How Matlab's mesh command will perform depends on your version of Matlab. If you scroll through the entries in z you'll find the complex entries. You can view the entries of z, much as we did the entries in y in Example 1, by typing z at the command prompt, followed by the Enter key. The false response (0 indicates 'false' in Matlab) is an indication that not all of the entries of z are real i.e., some entries are complex.
The beauty of this approach is the fact that Matlab's plot command ignores NaN's when plotting. Thus, we want to find the entries in the vector y whose real part does not equal itself.ġ.1055 1.0082 0.8964 0.7636 0.5961 0.3468 NaN If a number is real, then its real part equals itself. First, use Matlab's find command to find all entries that are not real. We can replace each complex entry in the vector y with a NaN. Hence the horizontal segments `y=0` at each end of the plot in Figure 1. Matlab's plot command ignores the imaginary part of any complex data and plots only the real part, which in the case of this example, is always zero. This output explains the strange horizontal segments at each end of the plot in Figure 1. Note especially that the real part of each of these complex numbers is zero. Note that there are complex entries at the beginning and end of the vector y.