Here I could put the description of the problem that I'm working on. Maybe some math. $$ \int_0^1 x^2 \, dx $$ and other stuff. Add more stuff $\sin(x)$.
for i in range(4,-5,-3): # range(start,stop,stride)
print(i)
# This would be a while loop.
i = -3
while i < 100:
print(i)
i = i+10
A = [];
for i in range(5):
A.append(i)
print(A)
print(A[1])
def power(x,y=2):
value = x**y
return value
print(f(4))
print(f())
power(4,1)
class Student:
def __init__(self, FirstName, LastName, Grade = "A"):
self.FirstName = FirstName
self.LastName = LastName
self.Grade = Grade
def showStudent(self):
print("Student Info: ")
print(" First Name: ", self.FirstName)
print(" Last Name: ", self.LastName)
print(" Grade : ", self.Grade)
S1 = Student("John","Chrispell")
S1.showStudent()
Let use a helix. For this I will use a radius $r$, parameter $p$, Starting point $t_0$, and Ending point $T$, and number of points $n$.
r = 5.0
p = 1.0
t0 = -10.0
T = 10.0
n = 100
from math import *
dt = (T - t0)/n
xpts = []
ypts = []
zpts = []
for i in range(n):
t = t0 + i*dt
xpts.append(r*cos(t))
ypts.append(r*sin(t))
zpts.append((p*t)/(2.0*pi))
The next block of code will save our set of points neatly to a file.
# Output the points.
f = open("Points.txt",'w')
for i in range(len(xpts)):
Point = str(int(xpts[i])) + " " + str(int(ypts[i])) + " " + str(int(zpts[i])) +"\n"
f.write(Point)
f.close()
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib inline
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
ax.scatter(xpts,ypts,zpts)
plt.show()
import numpy
import sympy
from matplotlib import rcParams
rcParams['font.family']='serif'
rcParams['font.size']='16'
from sympy import init_printing
init_printing()
x, f, nu, t = sympy.symbols('x f nu t')
x
f = x**2 + 3*x
f
fprime = f.diff(x)
fprime
phi = sympy.exp(-(x-4*t)**2/(4*nu*(t+1)))
phi
phiprime = phi.integrate(x)
phiprime
%%bash
cat Points.txt
Some stuff to interact with your plots and data quickly.
import numpy as np
import matplotlib.pyplot as plt
from __future__ import print_function
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets
from IPython.display import display
# This is a function plot x, y, and adds a title.
def plt_arrays(x,y,title="", color="red", linestyle="dashed", linewidth="2"):
fig = plt.figure()
axes = fig.add_subplot(111)
axes.plot(x,y,color=color,linestyle=linestyle,linewidth=linewidth)
axes.set_title(title)
axes.grid()
plt.show()
We should look at a function with the following form: $$ f(x) = a e^{(bx)} + c\sin(d\,x) $$ where $a, b, c,$ and $d$ are constants.
from math import *
def f(a,b,c,d, **kwargs):
x = np.linspace(-10,10,40)
y = a*np.exp(b*x) + c*np.sin(d*x)
title = "$f(x) = %s e^{(%sx)} + (%s)\sin(%s\,x) $" % (a,b,c,d)
plt_arrays(x,y,title = title, **kwargs)
%matplotlib inline
# Define the constants.
a = 1.0
b = 1.0
c = 1.0
d = 1.0
f(a,b,c,d)
i = interact(f,
a=(-10.,10),
b=(-10.,10),
c=(-10.,10),
d=(-10.,10),
color = ['red', 'blue','green','black'],
linestyle=["solid","dashed"],
linewidth=(1,5)
)