Tuesday, June 27, 2017

Python Plotting Tutorial -- Part 3

In this part, we'll see how to define functions and plot complex functions.



Defining Functions
It is often useful to define your own functions within a python program. A function can run any lines of code you desire, in addition to manipulating inputs and outputs. For the first example, we'll stick to a simple mathematical function.

Here we define a function of two inputs, then call it, save the output in a new variable, and print the output:
Many functions can also be applied to arrays. In this example, the inputs and outputs are both numpy arrays:


Plotting Complex Functions
Python has a built in syntax for manipulating complex numbers, using \(j = \sqrt{-1}\). It also lets you easily identify the magnitude, phase, and real and imaginary parts.

In order to visualize complex functions of a single real variable, we need to use two plots. This might be magnitude and phase, or real and imaginary part. In this example, we define the complex function \(z(s) = 2+e^{i s}\), then plot its magnitude and phase:

No comments:

Post a Comment