DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Plot Functions


2D plot in R

To visualize a function, we need plot it. A minimal example: curve(sin(x), -2*pi, 2*pi).

The following codes demonstrates the sigmoid function used by logistic regression:

$$f(x) = \frac{1}{1 + e^{-x}}$$

curve(1 / (1 + exp(-x)), -5, 5), or plot(function(x) { 1 / (1 + exp(-x)) }, -5, 5), or give the function a name:

sigmoid <- function(x) {
    1 / (1 + exp(-x))
}
plot(sigmoid, -5, 5)

3D Plot

How to plot multivariable function, such as \(f(x, y) = x^2 + y^2\) ?

Online Solutions

Using Cocalc

Create a new project and a new Sage Worksheet on CoCalc. Input the following codes:

%var u v
plot3d(2^(-u^2+v^2),[u,-2,2],[v,-2,2])

Using WolframAlpha

Input 3d plot z=x^2+y^2 into the inputbox of WolframAlpha.

Desktop App

Download and install Windows version of maxima (about 100MB) and install it. Then start Maxima (command line) from start menu. It also has Linux and Android distributions. In the console, input plot3d(2^(-u^2+v^2),[u,-2,2],[v,-2,2]); (notice the semicolon), the plot image is interactive.



Published

Jan 16, 2018

Last Updated

Jan 18, 2018

Category

Tech

Tags

  • maxima 1
  • plot 1
  • rlang 17
  • sage 1

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor