File:Metodo de Newton anime.gif

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Metodo_de_Newton_anime.gif (300 × 300 pixels, file size: 31 KB, MIME type: image/gif, looped, 7 frames, 14 s)

Captions

Captions

Add a one-line explanation of what this file represents

Summary

[edit]
Description
Português: Animação da interpretação geométrica do método de Newton.
English: Animation of the geometric interpretation of the Newton's method.
Date
Source Own work
Author Picknick

Código fonte

[edit]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''
Este trabalho está licenciado sob a Licença Creative Commons Atribuição-CompartilhaIgual 3.0 Não Adaptada. Para ver uma cópia desta licença, visite https://creativecommons.org/licenses/by-sa/3.0/ ou envie uma carta para Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

Author: Picknick - 08/2016
'''

import numpy as np
import scipy as sci
from scipy import optimize
import matplotlib.pyplot as plt
import matplotlib.animation as animation

#canvas
fig = plt.figure(figsize=(3,3), dpi=300, linewidth=0.0, facecolor="white")
#axes definitions
ax = plt.subplot(1,1,1)
ax.set_xlim(-1,3)
ax.set_ylim(-5,30)

ax.set_xticks([])
ax.set_yticks([])

ax.set_frame_on(False)

a = 0.25
b = 2.5

def fun(x):
    return (x+0.5)**3-1

def dfun(x):
    return 3*(x+0.5)**2

def rtan(x,x0):
    return dfun(x0)*(x-x0) + fun(x0)

x = np.array([0.,0.,0.])
x[0] = 2.15
x[1] = x[0] - fun(x[0])/dfun(x[0])
x[2] = x[1] - fun(x[1])/dfun(x[1])

def init():
    global ax
    ax.cla()

    ax.set_xlim(-1,3)
    ax.set_ylim(-5,30)

    ax.set_xticks([])
    ax.set_yticks([])

    ax.set_frame_on(False)

    ax.arrow(-1, 0, 4, 0, length_includes_head=True, facecolor='black', head_length=0.1, head_width=0.5)
    ax.text(2.75,-3.5,r"$x$")

    ax.arrow(0, -2, 0, 31, length_includes_head=True, facecolor='black', head_length=0.5, head_width=0.1)
    ax.text(-0.25, 26, r"$y$")

    xx = np.linspace (a, b)
    ax.plot(xx, fun(xx), lw=1.5)

    xstar = sci.optimize.fsolve(fun,a)
    ax.plot ([xstar, xstar], [0, 0], 'ro', markersize=3)
    ax.text (xstar - 0.25, 0.5, r"$x\!^{*}$")

def update(i):
    global ax, x
    print(i)
    if (i == 0):
        a = x[0]
        ax.plot ([0, a], [fun(a), fun(a)], color='gray', linestyle='dashed')
        ax.plot ([a, a], [fun(a), 0], color='gray', linestyle='dashed')
        ax.plot (a, fun(a), 'ko', markersize=3)
        ax.plot ([a, a], [-0.5, 0.5], color='black')
        ax.plot ([-0.1, 0.1], [fun(a), fun(a)], color='black')
        ax.text (-1, fun(a)-0.1, r"$f(x^{(1)})$")
        ax.text (a - 0.25, -3.5, r"$x^{(1)}$")
        
    if (i == 1):
        xx = np.linspace(x[0]-0.9,x[0]+0.4)
        ax.plot(xx,rtan(xx,x[0]),color="gray",lw=0.75)

    if (i == 2):
        ax.plot ([x[1], x[1]], [-0.5, 0.5], color='black')
        
    if (i == 3):
        a = x[1]
        ax.plot ([0, a], [fun(a), fun(a)], color='gray', linestyle='dashed')
        ax.plot ([a, a], [fun(a), 0], color='gray', linestyle='dashed')
        ax.plot (a, fun(a), 'ko', markersize=3)
        ax.plot ([-0.1, 0.1], [fun(a), fun(a)], color='black')
        ax.text (-1, fun(a)-0.1, r"$f(x^{(2)})$")
        ax.text (a - 0.25, -3.5, r"$x^{(2)}$")
        
    if (i == 4):
        xx = np.linspace(x[1]-0.6,x[1]+0.7)
        ax.plot(xx,rtan(xx,x[1]),color="gray",lw=0.75)
        
    if (i == 5):
        ax.plot ([x[2], x[2]], [-0.5, 0.5], color='black')

    if (i == 6):
        a = x[2]
        ax.plot ([a, a], [-0.5, 0.5], color='black')
        ax.text (a - 0.25, -3.5, r"$x^{(3)}$")

anime = animation.FuncAnimation(fig, update, np.arange(7), interval=2000, repeat=True, init_func=init, repeat_delay=1000)
anime.save('metodo_de_Newton_anime.gif', writer='imagemagick')

Licensing

[edit]
I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current00:32, 2 September 2016Thumbnail for version as of 00:32, 2 September 2016300 × 300 (31 KB)Picknick (talk | contribs)User created page with UploadWizard

The following page uses this file:

File usage on other wikis

The following other wikis use this file: