Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]

Type "copyright", "credits" or "license" for more information.


IPython 4.2.0 -- An enhanced Interactive Python.

? -> Introduction and overview of IPython's features.

%quickref -> Quick reference.

help -> Python's own help system.

object? -> Details about 'object', use 'object??' for extra details.

%guiref -> A brief reference about the graphical user interface.


In [1]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')


In [2]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

The root of x^2 is 0.0007812499999999964


In [3]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

The root of x^2 is 9.765624999999358e-05


In [4]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

The root of x^2 is 9.765625000000625e-05


In [5]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

Traceback (most recent call last):


File "<ipython-input-5-c735c49cfbb1>", line 1, in <module>

runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')


File "C:\Apps\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile

execfile(filename, namespace)


File "C:\Apps\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile

exec(compile(f.read(), filename, 'exec'), namespace)


File "//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py", line 18, in <module>

t = x - x2(x) / fprime(x2, x)


File "//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py", line 6, in fprime

def fprime(f, x, h=1e-5):


KeyboardInterrupt



In [6]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

The root of x^2 is 9.765625000000625e-05


In [7]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

The root of x^2 is 9.765625000000625e-05

We needed 10 iterations to converge


In [8]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

The root of x^2 is 0.0031250000000001598

We needed 5 iterations to converge


In [9]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

The root of x^2 is 0.0031250000000001598

We needed 5 iterations to converge


In [10]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

The root of x^2 is 9.765625000000625e-05

We needed 10 iterations to converge


In [11]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')

The root of x^2 is 9.765625000000625e-05

The function value at root is 9.536743164063721e-09

We needed 10 iterations to converge


In [12]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')


In [13]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')



In [14]: %matplotlib qt


In [15]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8/Lecture8.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture8')


In [16]: help(pylab.savefig)

Help on function savefig in module matplotlib.pyplot:


savefig(*args, **kwargs)

Save the current figure.


Call signature::


savefig(fname, dpi=None, facecolor='w', edgecolor='w',

orientation='portrait', papertype=None, format=None,

transparent=False, bbox_inches=None, pad_inches=0.1,

frameon=None)


The output formats available depend on the backend being used.


Arguments:


*fname*:

A string containing a path to a filename, or a Python

file-like object, or possibly some backend-dependent object

such as :class:`~matplotlib.backends.backend_pdf.PdfPages`.


If *format* is *None* and *fname* is a string, the output

format is deduced from the extension of the filename. If

the filename has no extension, the value of the rc parameter

``savefig.format`` is used.


If *fname* is not a string, remember to specify *format* to

ensure that the correct backend is used.


Keyword arguments:


*dpi*: [ *None* | ``scalar > 0`` | 'figure']

The resolution in dots per inch. If *None* it will default to

the value ``savefig.dpi`` in the matplotlibrc file. If 'figure'

it will set the dpi to be the value of the figure.


*facecolor*, *edgecolor*:

the colors of the figure rectangle


*orientation*: [ 'landscape' | 'portrait' ]

not supported on all backends; currently only on postscript output


*papertype*:

One of 'letter', 'legal', 'executive', 'ledger', 'a0' through

'a10', 'b0' through 'b10'. Only supported for postscript

output.


*format*:

One of the file extensions supported by the active

backend. Most backends support png, pdf, ps, eps and svg.


*transparent*:

If *True*, the axes patches will all be transparent; the

figure patch will also be transparent unless facecolor

and/or edgecolor are specified via kwargs.

This is useful, for example, for displaying

a plot on top of a colored background on a web page. The

transparency of these patches will be restored to their

original values upon exit of this function.


*frameon*:

If *True*, the figure patch will be colored, if *False*, the

figure background will be transparent. If not provided, the

rcParam 'savefig.frameon' will be used.


*bbox_inches*:

Bbox in inches. Only the given portion of the figure is

saved. If 'tight', try to figure out the tight bbox of

the figure.


*pad_inches*:

Amount of padding around the figure when bbox_inches is

'tight'.


*bbox_extra_artists*:

A list of extra artists that will be considered when the

tight bbox is calculated.



In [17]: x = [1, 2, 3, 4]


In [18]: x**2]

File "<ipython-input-18-fa5be261d9f8>", line 1

x**2]

^

SyntaxError: invalid syntax



In [19]: x**2

Traceback (most recent call last):


File "<ipython-input-19-c87530a60b58>", line 1, in <module>

x**2


TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'



In [20]: import numpy as np


In [21]: x = np.arange(0, 5, 1)


In [22]: x

Out[22]: array([0, 1, 2, 3, 4])


In [23]: x**2

Out[23]: array([ 0, 1, 4, 9, 16])


In [24]: x = [1, 2, 3, 4]


In [25]: x**2

Traceback (most recent call last):


File "<ipython-input-25-c87530a60b58>", line 1, in <module>

x**2


TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'



In [26]: x = np.array(x)


In [27]: x

Out[27]: array([1, 2, 3, 4])


In [28]: x**2

Out[28]: array([ 1, 4, 9, 16])


In [29]: