Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168703
Image: ubuntu2004
#Simple 1st order differential equation (o.d.e): #dx/dt=y #dy/dt=-x #initial conditions: x=1,y=0 #Let x=sin(t), y=cos(t), and t=pi/2 #Therefore: x(pi/2)=sin(pi/2)=1 and y(pi/2)=cos(pi/2)=0
#Exact Solution to o.d.e.
t=var('t') #Defines t as a dummy variable.
p1=plot(sin(t),-2*pi,2*pi) #2D Plot of sin(t) vs t.
#Information to display on sin(t) vs t plot: title=text("2D Plot: sin(t) vs t", (2.6,1.5), rgbcolor='black',vertical_alignment="top") curve=text("x=sin(t)", (-5,1.2), rgbcolor='black',vertical_alignment="top") exact_solution=point((pi/2,1),rgbcolor='red',pointsize=25) #Places red point at exact (initial cond) solution,(pi/2,1) point_location=text("Exact Solution (pi/2,1)", (3,1.2), rgbcolor='black',vertical_alignment="top")
show(p1+title+curve+exact_solution+point_location, axes_labels=('t','x'))
p2=plot(cos(t),-2*pi,2*pi) #2D plot of cos(t) vs t.
#Information to display on cos(t) vs t plot: title=text("2D Plot: cos(t) vs t", (2.65,1.5), rgbcolor='black',vertical_alignment="top") curve=text("y=cos(t)", (-5,1.2), rgbcolor='black',vertical_alignment="top") exact_solution=point((pi/2,0),rgbcolor='red',pointsize=25) #Places red point at exact (initial cond) solution,(pi/2,0) point_location=text("Exact Solution (pi/2,0)", (3,1.2), rgbcolor='black',vertical_alignment="top") initial_condition_location=arrow((2,1),(pi/2,0.1), color='red') #Places arrow at location of initial condition
show(p2+title+curve+exact_solution+point_location+initial_condition_location, axes_labels=('t','y'))
#Use 2nd Order Runge-Kutta to integrate equation dy/dt=-x, where y=cos(t). #Therefore, equation to be integrated is -sin(t)+x
def xfunc(t,x): #x function with independent variable t defined. return float(-sin(t)+x)
import scipy #Transfer files from scipy (open source library of algorithms and mathematical tools from Python programming language) into this worksheet. def rk2x(x0,t0,tn,dt): #2nd Order Runge-Kutta defined. time = scipy.arange(t0,tn,dt) #Creates array range (arange) of time values. x=[] #Stores index of refraction values. for t in time: x.append(x0) #Attach results (x0) at end of variable x. k1=xfunc(t,x0) k2=xfunc(t+0.5*dt,x0+0.5*k1) x0=x0+(k1+k2)/2 return time,x
rk2x(1, float(pi/2), 2, 0.01) #Function call to 2nd Order Runge-Kutta with predetermined assignments.
(array([ 1.57079633, 1.58079633, 1.59079633, 1.60079633, 1.61079633, 1.62079633, 1.63079633, 1.64079633, 1.65079633, 1.66079633, 1.67079633, 1.68079633, 1.69079633, 1.70079633, 1.71079633, 1.72079633, 1.73079633, 1.74079633, 1.75079633, 1.76079633, 1.77079633, 1.78079633, 1.79079633, 1.80079633, 1.81079633, 1.82079633, 1.83079633, 1.84079633, 1.85079633, 1.86079633, 1.87079633, 1.88079633, 1.89079633, 1.90079633, 1.91079633, 1.92079633, 1.93079633, 1.94079633, 1.95079633, 1.96079633, 1.97079633, 1.98079633, 1.99079633]), [1, 1.0000062499869791, 1.0001078111035242, 1.0005488118451449, 1.0018785200780911, 1.0053327547560502, 1.013692062286089, 1.0332126133566466, 1.0779707208063913, 1.1796380048362707, 1.4094755147449907, 1.927820502843461, 3.0954316657731566, 5.7240159374845376, 11.639913773451845, 24.952391040170976, 54.907295766545545, 122.30778583452259, 273.96096628304116, 615.18282324193638, 1382.9343252832441, 3110.3776514616584, 6997.1277044055851, 15742.318014772034, 35418.999026270154, 79691.534236964217, 179304.74151720537, 403434.461074978, 907726.3333779294, 2042383.0494779362, 4595360.6642413791, 10339560.30111726, 23264009.48786547, 52344020.161945388, 117774044.18264021, 264991598.23333675, 596231094.85165489, 1341519962.2472391, 3018419913.8917885, 6791444805.0966263, 15280750810.312229, 34381689322.05217, 77358800973.471985])
t2,x2=rk2x(1, float(pi/2), 2, 0.01) #Variable t2,x2 is assigned time and x values.
#Information to display on -sin(t)+x plot using RK2: title=text("RK2 solution of -sin(t)+x", (1.9,88000000000), rgbcolor='black',horizontal_alignment="right") initial_condition=point((pi/2,1),rgbcolor='red',pointsize=25) #Places red point at initial condition,(pi/2,1)
plxtRK2=list_plot(zip(t2,x2),'r') show(plxtRK2+title+initial_condition, axes_labels=('t','x'))
import numpy as np #Transfer files from fundamental library numpy (N-dimensional array manipulation) used with Python. import matplotlib.pyplot as plt #Transfer files from matplotlib.pyplot (plotting library) used with Python language. x = t2 y = x2 fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) ax.set_xlim(1.4, 2.2) ax.set_ylim(0, 80000000000) ax.set_xlabel('Increasing time (t)') ax.set_ylabel('Integrated Eqn: -sin(t)+x') ax.set_title('RK2 Soln to Integrated Eqn: -sin(t)+x') ax.grid() xdata, ydata = 1.92079633, 264991598.23333675 xdisplay, ydisplay = ax.transData.transform((xdata, ydata)) bbox = dict(boxstyle="round", fc="0.8") #bbox or bounding box arrowprops = dict(arrowstyle = "->",connectionstyle = "angle,angleA=0,angleB=90,rad=10") offset = 72 ax.annotate('data = (%.1f, %.1f)'%(xdata, ydata), (xdata, ydata), xytext=(-3*offset, offset), textcoords='offset points', bbox=bbox, arrowprops=arrowprops) plt.savefig('myfig.png')
#Use 4th Order Runge-Kutta to integrate equation dy/dt=-x, where y=cos(t). #Therefore, equation to be integrated is -sin(t)+x
import scipy #Transfer files from scipy (open source library of algorithms and mathematical tools from Python programming language) into this worksheet. def rk4x(x0,t0,tn,dt): #4th Order Runge-Kutta defined. time = scipy.arange(t0,tn,dt) #Creates array range (arange) of time values. x=[] #Stores index of refraction values. for t in time: x.append(x0) #Attach results (x0) at end of variable x. k1 = xfunc(t,x0) k2 = xfunc(t+0.5*dt, x0 + 0.5*dt*k1) k3 = xfunc(t+0.5*dt, x0 + 0.5*dt*k2) k4 = xfunc(t+dt, x0 + dt*k3) x0 = x0+(dt/6.0)*(k1 + 2.0*k2 + 2.0*k3 + k4) return time,x
rk4x(1, float(pi/2), 2, 0.01) #Function call to 4th Order Runge-Kutta with predetermined assignments.
(array([ 1.57079633, 1.58079633, 1.59079633, 1.60079633, 1.61079633, 1.62079633, 1.63079633, 1.64079633, 1.65079633, 1.66079633, 1.67079633, 1.68079633, 1.69079633, 1.70079633, 1.71079633, 1.72079633, 1.73079633, 1.74079633, 1.75079633, 1.76079633, 1.77079633, 1.78079633, 1.79079633, 1.80079633, 1.81079633, 1.82079633, 1.83079633, 1.84079633, 1.85079633, 1.86079633, 1.87079633, 1.88079633, 1.89079633, 1.90079633, 1.91079633, 1.92079633, 1.93079633, 1.94079633, 1.95079633, 1.96079633, 1.97079633, 1.98079633, 1.99079633]), [1, 1.00000016708351, 1.00000134000034, 1.00000453375051, 1.00001077333402, 1.00002109375097, 1.00003654000151, 1.00005816708607, 1.00008704000543, 1.00012423376095, 1.00017083335489, 1.00022793379078, 1.00029664007385, 1.00037806721165, 1.00047334021469, 1.00058359409733, 1.00070997387864, 1.00085363458358, 1.00101574124423, 1.00119746890123, 1.00140000260544, 1.00162453741970, 1.00187227842089, 1.00214444070218, 1.00244224937551, 1.00276693957429, 1.00311975645642, 1.00350195520749, 1.00391480104435, 1.00435956921893, 1.00483754502235, 1.00535002378938, 1.00589831090322, 1.00648372180065, 1.00710758197747, 1.00777122699440, 1.00847600248328, 1.00922326415376, 1.01001437780030, 1.01085071930967, 1.01173367466886, 1.01266463997345, 1.01364502143643])
t4,x4=rk4x(1, float(pi/2), 2, 0.01) #Variable t4,x4 is assigned time and x values.
#Information to display on -sin(t)+x plot (RK4): title=text("RK4 solution of -sin(t)+x", (1.8,1.014), rgbcolor='black',vertical_alignment="top") initial_condition=point((pi/2,1),rgbcolor='red',pointsize=25) #Places red point at initial condition,(pi/2,1)
plxtRK4=list_plot(zip(t4,x4),'r') show(plxtRK4+title+initial_condition, axes_labels=('t','x'))
import numpy as np #Transfer files from fundamental library numpy (N-dimensional array manipulation) used with Python. import matplotlib.pyplot as plt #Transfer files from matplotlib.pyplot (plotting library) used with Python language. x = t4 y = x4 fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) ax.set_xlim(1.4, 2.2) ax.set_ylim(1, 1.012) ax.set_xlabel('Increasing time (t)') ax.set_ylabel('Integrated Eqn: -sin(t)+x') ax.set_title('RK4 Soln to Integrated Eqn: -sin(t)+x') ax.grid() xdata, ydata = 1.63079633, 1.00003654000151 xdisplay, ydisplay = ax.transData.transform((xdata, ydata)) bbox = dict(boxstyle="round", fc="0.8") #bbox or bounding box arrowprops = dict(arrowstyle = "->",connectionstyle = "angle,angleA=0,angleB=90,rad=10") offset = 72 ax.annotate('data = (%.1f, %.1f)'%(xdata, ydata), (xdata, ydata), xytext=(-1*offset, offset), textcoords='offset points', bbox=bbox, arrowprops=arrowprops) plt.savefig('myfig.png')
#Plot of solution from 2nd order Runge-Kutta approximation using function -sin(t)+x #This plot has axes range adjusted to give a different view of the solution
new_plxtRK2=plxtRK2 #Name of new plot displaying solution of -sin(t)+x from 2nd order Runge-Kutta approximation
#Information to be displayed on 2nd order Runge-Kutta solution of -sin(t)+x with predefined axes range title1=text("RK2 solution of -sin(t)+x with",(5.2,6),rgbcolor='black',vertical_alignment="top") title2=text("predefined axis range",(5.2,5.5),rgbcolor='black',vertical_alignment="top")
plxtRK2_new_axes_range=new_plxtRK2+title1+title2 #Variable plxtRK2_new_axes_range set equal to new_plxt2, title, etc. plxtRK2_new_axes_range.set_axes_range(-2*pi,2*pi, -1,5) #Axes range defined for plxtRK2_new_axes_range.
show(plxtRK2_new_axes_range,axes_labels=('t','x')) #Displays RK2 solution of -sin(t)+x with axes range predefined.
#Plot of solution from 2nd order Runge-Kutta approximation to exact solution of o.d.e #Solution of 2nd order Runge-Kutta approximation: -sin(t)+x #Exact Solution: x=sin(t), or x(pi/2)=1
#Information to display on -sin(t)+x vs sin(pi/2) plot (RK2): title1=text("RK2 Solution: -sin(t)+x vs",(5,6), rgbcolor='black', vertical_alignment="top") title2=text("Exact Solution: sin(pi/2)", (5,5.65), rgbcolor='black',vertical_alignment="top") exact_solution=point((pi/2,1),rgbcolor='red',pointsize=25) #Places red point at exact solution of sin(t) or at (pi/2,1)
p1=plot(sin(t),-2*pi,2*pi,linestyle='--') #2D Plot of sin(t) vs t. RK2_xfunc_vs_exact=plxtRK2+p1 #Set plot of RK2 solution of -sin(t)+x plus sin(t) to RK2_xfunc_vs_exact variable name plxtRK2_vs_p1=RK2_xfunc_vs_exact+title1+title2+exact_solution #Plot of RK2 solution of function -sin(t)+x vs sin(t) plxtRK2_vs_p1.set_axes_range(-2*pi,2*pi, -1,5) #Axes range of RK2 solution of function -sin(t)+x vs sin(t) defined show(plxtRK2_vs_p1,axes_labels=('t','x'))
#Plot of solution from 4th order Runge-Kutta approximation to exact solution of o.d.e #Solution of 4th order Runge-Kutta approximation: -sin(t)+x #Exact Solution: x=sin(t), or x(pi/2)=1
#Information to display on -sin(t)+x vs sin(pi/2) plot (RK4): title1=text("RK4 Solution: -sin(t)+x vs",(5,1.05), rgbcolor='black', vertical_alignment="top") title2=text("Exact Solution: sin(pi/2)", (5,.9), rgbcolor='black',vertical_alignment="top") exact_solution=point((pi/2,1),rgbcolor='red',pointsize=25) #Places red point at exact solution of sin(t) or at (pi/2,1)
p1=plot(sin(t),-2*pi,2*pi,linestyle='--') #2D Plot of sin(t) vs t. RK4_xfunc_vs_exact=plxtRK4+p1 #Set plot of RK4 solution of -sin(t)+x plus sin(t) to RK4_xfunc_vs_exact variable name plxtRK4_vs_p1=RK4_xfunc_vs_exact+title1+title2+exact_solution #Plot of RK4 solution of function -sin(t)+x vs sin(t) plxtRK4_vs_p1.set_axes_range(-2*pi,2*pi, -1,1.03) #Axes range of RK2 solution of function -sin(t)+x vs sin(t) defined show(plxtRK4_vs_p1,axes_labels=('t','x'))
def yfunc(t,y): #y function with independent variable t defined. return float(cos(t)-y)
import scipy #Transfer files from scipy (open source library of algorithms and mathematical tools from Python programming language) into this worksheet. def rk2y(y0,t0,tn,dt): #2nd Order Runge-Kutta defined. time = scipy.arange(t0,tn,dt) # Creates array range (arange) of time values. y=[] #Stores index of refraction values. for t in time: y.append(y0) #Attach results (y0) at end of variable y. k1=yfunc(t0,y0) k2=yfunc(t+0.5*dt, y0+0.5*k1) y0=y0+(k1+k2)/2 return time,y
rk2y(0, float(pi/2), 2, 0.01) #Function call to 2nd Order Runge-Kutta with predetermined assignments.
(array([ 1.57079633, 1.58079633, 1.59079633, 1.60079633, 1.61079633, 1.62079633, 1.63079633, 1.64079633, 1.65079633, 1.66079633, 1.67079633, 1.68079633, 1.69079633, 1.70079633, 1.71079633, 1.72079633, 1.73079633, 1.74079633, 1.75079633, 1.76079633, 1.77079633, 1.78079633, 1.79079633, 1.80079633, 1.81079633, 1.82079633, 1.83079633, 1.84079633, 1.85079633, 1.86079633, 1.87079633, 1.88079633, 1.89079633, 1.90079633, 1.91079633, 1.92079633, 1.93079633, 1.94079633, 1.95079633, 1.96079633, 1.97079633, 1.98079633, 1.99079633]), [0, -0.0024999895833462543, -0.0081247161490005139, -0.014529876994606204, -0.021128896550819561, -0.027774631156534925, -0.034429795302667515, -0.041084568243058103, -0.04773599569713563, -0.054382840325491857, -0.061024294398651563, -0.067659658014104077, -0.074288258700357879, -0.080909431367703274, -0.087522513345599934, -0.094126843191663145, -0.10072176044348746, -0.10730660560611233, -0.11388072019832604, -0.1204434468136021, -0.12699412918461148, -0.13353211224854183, -0.14005674221252662, -0.14656736661900438, -0.15306333441095948, -0.1595439959970259, -0.16600870331644552, -0.1724568099038736, -0.17888767095402486, -0.18530064338615326, -0.19169508590835971, -0.19807035908172071, -0.20442582538423165, -0.21076084927455843, -0.2170747972555912, -0.2233670379377935, -0.22963694210234056, -0.23588388276404088, -0.24210723523403407, -0.24830637718225917, -0.25448068869968737, -0.26062955236031216, -0.26675235328289149])
t2,y2=rk2y(0, float(pi/2), 2, 0.01) #Variable t2,y2 is assigned time and y values.
#Information to display on cos(t)-y plot (RK2): title=text("RK2 solution of cos(t)-y", (1.86,0.07), rgbcolor='black',vertical_alignment="top") initial_condition=point((pi/2,0),rgbcolor='red',pointsize=25) #Places red point at initial condition,(pi/2,0)
plxtRK2=list_plot(zip(t2,y2),'r') show(plxtRK2+title+initial_condition, axes_labels=('t','y'))
import numpy as np #Transfer files from fundamental library numpy (N-dimensional array manipulation) used with Python. import matplotlib.pyplot as plt #Transfer files from matplotlib.pyplot (plotting library) used with Python language. x = t2 y = y2 fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) ax.set_xlim(1.4, 2.2) ax.set_ylim(-0.3, 0.1) ax.set_xlabel('Increasing time (t)') ax.set_ylabel('Integrated Eqn: cos(t)-y') ax.set_title('RK2 Soln to Integrated Eqn: cos(t)-y') ax.grid() xdata, ydata = 1.58079633, -0.0024999895833462543 xdisplay, ydisplay = ax.transData.transform((xdata, ydata)) bbox = dict(boxstyle="round", fc="0.8") #bbox or bounding box arrowprops = dict(arrowstyle = "->",connectionstyle = "angle,angleA=0,angleB=90,rad=10") offset = 20 ax.annotate('data = (%.1f, %.1f)'%(xdata, ydata), (xdata, ydata), xytext=(-1*offset, offset), textcoords='offset points', bbox=bbox, arrowprops=arrowprops) plt.savefig('myfig.png')
import scipy #Transfer files from scipy (open source library of algorithms and mathematical tools from Python programming language) into this worksheet. def rk4y(y0,t0,tn,dt): #4th Order Runge-Kutta defined. time = scipy.arange(t0,tn,dt) #Creates array range (arange) of time values. y=[] #Stores index of refraction values. for t in time: y.append(y0) #Attach results (y0) at end of variable y. k1 = yfunc(t,y0) k2 = yfunc(t+0.5*dt, y0 + 0.5*dt*k1) k3 = yfunc(t+0.5*dt, y0 + 0.5*dt*k2) k4 = yfunc(t+dt, y0 + dt*k3) y0 = y0 +(dt/6.0)*(k1 + 2.0*k2 + 2.0*k3 + k4) return time,y
rk4y(0, float(pi/2), 2, 0.01) #Function call to 4th Order Runge-Kutta with predetermined assignments.
(array([ 1.57079633, 1.58079633, 1.59079633, 1.60079633, 1.61079633, 1.62079633, 1.63079633, 1.64079633, 1.65079633, 1.66079633, 1.67079633, 1.68079633, 1.69079633, 1.70079633, 1.71079633, 1.72079633, 1.73079633, 1.74079633, 1.75079633, 1.76079633, 1.77079633, 1.78079633, 1.79079633, 1.80079633, 1.81079633, 1.82079633, 1.83079633, 1.84079633, 1.85079633, 1.86079633, 1.87079633, 1.88079633, 1.89079633, 1.90079633, 1.91079633, 1.92079633, 1.93079633, 1.94079633, 1.95079633, 1.96079633, 1.97079633, 1.98079633, 1.99079633]), [0, -0.0000498333340276020, -0.000198666668124114, -0.000445500003036134, -0.000789333341660262, -0.00122916669150976, -0.00176400006815122, -0.00239283349960124, -0.00311466703167308, -0.00392850073426332, -0.00483333470856858, -0.00582816909522210, -0.00691200408334051, -0.00808383992047045, -0.00934267692342526, -0.0106875154900017, -0.0121173561115666, -0.0136311993865036, -0.0152280460345100, -0.0169068969117334, -0.0186667530267384, -0.0205066155572937, -0.0224254858679688, -0.0244223655285313, -0.0264962563331332, -0.0286461603202790, -0.0308710797935620, -0.0331700173431624, -0.0355419758680946, -0.0379859585991946, -0.0405009691228386, -0.0430860114053803, -0.0457400898183003, -0.0484622091640539, -0.0512513747026110, -0.0541065921786752, -0.0570268678495741, -0.0600112085138095, -0.0630586215402586, -0.0661681148980160, -0.0693386971868657, -0.0725693776683751, -0.0758591662975983])
t4,y4=rk4y(0, float(pi/2), 2, 0.01) #Variable t4,y4 is assigned time and y values.
#Information to display on cos(t)-y plot (RK4): title=text("RK4 solution of cos(t)-y", (1.8,0.01), rgbcolor='black',vertical_alignment="top") initial_condition=point((pi/2,0),rgbcolor='red',pointsize=25) #Places red point at initial condition,(pi/2,0)
plxtRK4=list_plot(zip(t4,y4),'r') show(plxtRK4+title+initial_condition, axes_labels=('t','y'))
import numpy as np #Transfer files from fundamental library numpy (N-dimensional array manipulation) used with Python. import matplotlib.pyplot as plt #Transfer files from matplotlib.pyplot (plotting library) used with Python language. x = t4 y = y4 fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) ax.set_xlim(1.4, 2.2) ax.set_ylim(-0.09, 0.03) ax.set_xlabel('Increasing time (t)') ax.set_ylabel('Integrated Eqn: cos(t)-y') ax.set_title('RK4 Soln to Integrated Eqn: cos(t)-y') ax.grid() xdata, ydata = 1.58079633, -0.0000498333340276020 xdisplay, ydisplay = ax.transData.transform((xdata, ydata)) bbox = dict(boxstyle="round", fc="0.8") #bbox or bounding box arrowprops = dict(arrowstyle = "->",connectionstyle = "angle,angleA=0,angleB=90,rad=10") offset = 50 ax.annotate('data = (%.1f, %.1f)'%(xdata, ydata), (xdata, ydata), xytext=(-1*offset, offset), textcoords='offset points', bbox=bbox, arrowprops=arrowprops) plt.savefig('myfig.png')
#Plot of solution from 2nd order Runge-Kutta approximation to exact solution of o.d.e #Solution of 2nd order Runge-Kutta approximation: cos(t)-y #Exact Solution: y=cos(t), or y(pi/2)=0
#Information to display on cos(t)-y vs cos(pi/2) plot (RK2): title1=text("RK2 Solution: cos(t)-y vs",(3,1.2), rgbcolor='black', vertical_alignment="top") title2=text("Exact Solution: cos(pi/2)", (3,1.05), rgbcolor='black',vertical_alignment="top") exact_solution=point((pi/2,0),rgbcolor='red',pointsize=25) #Places red point at exact solution of cos(t) or at (pi/2,0)
p2=plot(cos(t),-2*pi,2*pi,linestyle='--') #2D Plot of cos(t) vs t. RK2_yfunc_vs_exact=plxtRK2+p2 #Set plot of RK2 solution of cos(t)-y plus cos(t) to RK2_yfunc_vs_exact variable name plxtRK2_vs_p2=RK2_yfunc_vs_exact+title1+title2+exact_solution #Plot of RK2 solution of function cos(t)-y vs cos(t) plxtRK2_vs_p2.set_axes_range(-2*pi,2*pi, -1,1) #Axes range of RK2 solution of function cos(t)-y vs cos(t) defined show(plxtRK2_vs_p2,axes_labels=('t','y'))
#Plot of solution from 4th order Runge-Kutta approximation to exact solution of o.d.e #Solution of 4th order Runge-Kutta approximation: cos(t)-y #Exact Solution: y=cos(t), or y(pi/2)=0
#Information to display on cos(t)-y vs cos(pi/2) plot (RK4): title1=text("RK4 Solution: cos(t)-y vs",(3,1.2), rgbcolor='black', vertical_alignment="top") title2=text("Exact Solution: cos(pi/2)", (3,1.05), rgbcolor='black',vertical_alignment="top") exact_solution=point((pi/2,0),rgbcolor='red',pointsize=25) #Places red point at exact solution of cos(t) or at (pi/2,0)
p2=plot(cos(t),-2*pi,2*pi,linestyle='--') #2D Plot of cos(t) vs t. RK4_yfunc_vs_exact=plxtRK4+p2 #Set plot of RK4 solution of cos(t)-y plus cos(t) to RK4_yfunc_vs_exact variable name plxtRK4_vs_p2=RK4_yfunc_vs_exact+title1+title2+exact_solution #Plot of RK4 solution of function cos(t)-y vs cos(t) plxtRK4_vs_p2.set_axes_range(-2*pi,2*pi, -1,1) #Axes range of RK4 solution of function cos(t)-y vs cos(t) defined show(plxtRK4_vs_p2,axes_labels=('t','y'))