Jump to content

File:Rosenbrock3.gif

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Rosenbrock3.gif (600 × 400 pixels, file size: 1.14 MB, MIME type: image/gif, looped, 41 frames, 8.2 s)

Summary

Description
English: Animation of Rosenbrock's function of three variables.
Date
Source Own work
Author nicoguaro
GIF development
InfoField
 
This plot was created with Matplotlib.
Source code
InfoField

Python code

"""
Animation of the Rosenbrock function of three variables
"""
import numpy as np
from scipy.optimize import rosen
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation

Axes3D
plt.rcParams["font.size"] = 10
plt.rcParams["mathtext.fontset"] = "cm"

x1, x2 = np.mgrid[-2.5:2.5:51j, -2.5:2.5:51j]
x3  = np.linspace(-2.5, 2.5, 21)
x3  = np.append(x3, x3[-2::-1])
fun = rosen([x1, x2, x3[0]])

fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(111, projection='3d')
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) 
ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) 
ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))

def data_gen(num):
    fun = rosen([x1, x2, x3[num]])
    ax.cla()
    surf = ax.plot_wireframe(x1, x2, fun/1000, linewidth=1, color="#3c3c3c",
                         rstride=51, cstride=51)
    contour = ax.contour(x1, x2, fun/1000, 20)
    ax.set_xlabel(r"$x_1$", fontsize=12)
    ax.set_ylabel(r"$x_2$", fontsize=12)
    ax.set_zlabel(r"$f(x_1, x_2, x_3)/10^3$", fontsize=12)
    ax.set_title(r"$x_3 = {}$".format(x3[num]), fontsize=12, y=1.08)
    ax.set_xlim(-2.5, 2.5)
    ax.set_ylim(-2.5, 2.5)
    ax.set_zlim(0, 16)
    ax.view_init(elev=45, azim=-45)
    return surf, contour

ani = animation.FuncAnimation(fig, data_gen, range(41))
ani.save("rosenbrock3.gif", writer='imagemagick')
plt.show()

Licensing

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.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

26 June 2018

File history

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

Date/TimeThumbnailDimensionsUserComment
current17:24, 26 June 2018Thumbnail for version as of 17:24, 26 June 2018600 × 400 (1.14 MB)NicoguaroImprove lines width
23:36, 9 December 2017Thumbnail for version as of 23:36, 9 December 2017840 × 600 (255 KB)PasimiUser created page with UploadWizard

The following 2 pages use this file:

Global file usage

The following other wikis use this file: