File:Metodo das secantes anime.gif
Metodo_das_secantes_anime.gif (300 × 300 pixels, file size: 36 KB, MIME type: image/gif, looped, 7 frames, 14 s)
Captions
Captions
Summary
[edit]DescriptionMetodo das secantes anime.gif |
Português: Animação sobre o método das secantes.
English: Animation about the secant method. |
Date | |
Source | Own work |
Author | Picknick |
Código fonte
[edit]<syntaxhighligh lang=python>
- !/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 - 09/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.5) ax.set_ylim(-5,30)
ax.set_xticks([]) ax.set_yticks([])
ax.set_frame_on(False)
a = 0.25 b = 2.75
def fun(x):
return 0.8*(x+0.5)**3-1
def rsec(x,x0,x1):
return (fun(x1)-fun(x0))/(x1-x0)*(x-x1) + fun(x1)
x = np.array([0.,0.,0.,0.]) x[0] = 2.65 x[1] = 2.15 x[2] = x[1] - fun(x[1])*(x[1]-x[0])/(fun(x[1])-fun(x[0])) x[3] = x[2] - fun(x[2])*(x[2]-x[1])/(fun(x[2])-fun(x[1]))
def init():
global ax ax.cla()
ax.set_xlim(-1,3.5) ax.set_ylim(-5,30)
ax.set_xticks([]) ax.set_yticks([])
ax.set_frame_on(False)
ax.arrow(-1, 0, 4.5, 0, length_includes_head=True, facecolor='black', head_length=0.1, head_width=0.5) ax.text(3.25,-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.4, 27.5, 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.05, 0.05], [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)}$")
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 ([a, a], [-0.5, 0.5], color='black') ax.plot ([-0.05, 0.05], [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 == 1): xx = np.linspace(x[1]-0.75,x[1]+0.7) ax.plot(xx,rsec(xx,x[0],x[1]),color="gray",lw=0.75)
if (i == 2): ax.plot ([x[2], x[2]], [-0.5, 0.5], color='black') if (i == 3): a = x[2] 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.05, 0.05], [fun(a), fun(a)], color='black') ax.text (-1, fun(a)-0.1, r"$f(x^{(3)})$") ax.text (a - 0.2, -3.5, r"$x^{(3)}$") if (i == 4): xx = np.linspace(x[2]-0.5,x[2]+1) ax.plot(xx,rsec(xx,x[1],x[2]),color="gray",lw=0.75) if (i == 5): ax.plot ([x[3], x[3]], [-0.5, 0.5], color='black')
if (i == 6): a = x[3] ax.plot ([a, a], [-0.5, 0.5], color='black') ax.text (a - 0.3, -3.5, r"$x^{(4)}$")
anime = animation.FuncAnimation(fig, update, np.arange(7), interval=2000, repeat=True, init_func=init, repeat_delay=3000) anime.save('metodo_das_secantes_anime.gif', writer='imagemagick') </syntaxhighligh>
Licensing
[edit]![w:en:Creative Commons](https://upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/90px-CC_some_rights_reserved.svg.png)
![attribution](https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/24px-Cc-by_new_white.svg.png)
![share alike](https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/24px-Cc-sa_white.svg.png)
- 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/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 12:44, 3 September 2016 | ![]() | 300 × 300 (36 KB) | Picknick (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
The following page uses this file: