Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: LS30A-1 F19
Views: 205
Kernel: SageMath (stable)

Different versions of Hao

Week 01

LS30A LAB 1B/1D

TA: Hao Lee

LA: Evelyn Malamut

About TA

  • Name: Hao Lee

  • Major:

Making Iron Man Suit (Robotics)

  • What I look like?

drawing

*Fig. 1: Different versions of Hao (in case any unexpected transformation happens)

About Class

OH:

  • Mon. 10 AM - 11 AM

  • Tue. 1 PM - 2 PM

Location: TBA

Login to CoCalc!!

What is CoCalc

  • A platform to use SAGE

  • Online system, no environment setup is needed!

Why use SAGE?

  • Simplified version of Python

  • More math-friendly

Example (You don't need to know this)

How to plot sin(t)?

In python

import numpy as np from matplotlib import pyplot as plt t = np.linspace(0,10,100) plt.plot(t,np.sin(t))
[<matplotlib.lines.Line2D object at 0x7f018fed28d0>]
Image in a Jupyter notebook

In CoCalc (SAGE)

plot(sin(x),(x,0,10))
Image in a Jupyter notebook

SAGE is much simplier

How to use CoCalc?

Mach Operations

  • Plus: +

  • Minus: -

  • Multiply: *

  • Division: /

  • Things need to be evaluate first: (put it inside the parentheses)

100/3
100/3

Shortcut Commands!

  • Shift + Enter (Run this cell!)

  • Alt + Enter (Run this cell and create an empty cell!)

Fractions and Decimal Numbers

The default display format is fraction, but sometimes we prefer decimal numbers (easier to compare)

Just put a dot next to the number!

print(2./3) print(2/3.) print(2./3.)
0.666666666666667 0.666666666666667 0.666666666666667

Variables

Assign/Save Values

a = 5

"=" has different meaning in programming, it means "assigning the value on the right to the variable on the left"

#Question: a = 4 a = a+1 # what is a?
print(a)
5

Functions

"Tasks we can do it again and again!!!"

Syntax of a Function:

function_name(inputs)

Build-in Functions

print(sqrt(3.)) print(log(10.))
1.73205080756888 2.30258509299405

Self-defined Functions

Consider define a function:
output=10input1+input2output = 10^{input_1}+input_2
def my_function(input1,input2): result = 10^input1+input2 return result

Nothing is process in the above function definition!

If you want to use it, you need to Call the function.

my_function(2,4)
104

Plot the Data

Sometimes we prefer to visualize the data

e.g., plot x3+2x+1x^3+2x+1

fig = plot(function,(x,x_min,x_max),options)

options are really "optional", you can leave it blank but still plot

p = plot(x^3+2*x+1,(x,-5,5)) show(p)
Image in a Jupyter notebook
p = plot(x^3+2*x+1,(x,-5,5),color='red') show(p)
Image in a Jupyter notebook

Plots can interacts with you!!

@interact def interact_plot(m=(0,5)): p1 = plot(x^3+m*x+1,(x,-5,5)) p2 = plot(m*x^2,(x,-5,5),color='red') show(p1+p2,ymax=100,ymin=-100)