An archive of Mark's Spring 2018 Numerical Analysis course.

Define and plot your own personalized function

mark

(5 pts)

Use the code here to generate your own personalized random function based on your student ID number. After doing so, respond to this question reporting the following information:

  • A nicely typeset version of your function,
  • The definition of your function in Python,
  • A plot of your function together with the line y=x over the interval [-2,2].
  • Use the previous plot to note if your function has roots or fixed points.
audrey

My randomly generated function is

f(x) = \sin^{3}{\left (x^{3} \right )}.

I can define that and do a quick computation in Python like so:

from numpy import sin, cos, exp
def f(x): return sin(x**3)**3
f(1)

# Out: 0.5958232365909556

With a little more work, I can plot it as well:

%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
x = np.linspace(-2,2,100)
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('my_pic.png')

my_pic

A quick look indicates that the function has about five roots in between -2 and 2 and that zero is both a root and a fixed point. It looks like zero is the only fixed point.

nathan

My random function is

\cos(x^9).

This function can be defined in Python as such:

from numpy import cos
def f(x):
    return cos(x**9)

It can be plotted in matplotlib like this:

import numpy as np
from matplotlib import pyplot as plt
x = np.arange(-2, 2, 0.001) #xmin, xmax, stepsize
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('plot.png')
plt.show()

plot
The function is almost constant for small x values, but it quickly becomes chaotic thereafter with an uncountable number of roots between -2 and 2. There is a single fixed point near x = 1.

mark

This looks awesome nathan! I edited just slightly to format your TeX input a little better. Rather than $cos(x^9)$, I input it as

$$
\cos(x^9)
$$

Note that the double dollar signs are on their own line. That’s not a standard LaTeX requirement but it’s the way the parser is implemented here.

dumptruckman

My random function is:

x^{3} + \sin{\left (x^{3} \right )} + \cos{\left (x^{3} \right )}

In Python this would look like:

from numpy import sin, cos
def f(x):
  return x**3 + sin(x**3) + cos(x**3)

A plot of the function over the interval [-2,2] using matplotlib looks like:

import numpy as np
from matplotlib import pyplot as plt
x = np.arange(-2, 2, 0.001)
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.show()

figure_1
The function appears to have 1 root over the interval [-2,2] and a single fixed point near x=-1.

brian

My randomly generated function is

f(x)=\sin^{9}(x)

This function can be defined in Python as follows:

from numpy import sin
def f(x): return sin(x)**9

Further, I can plot this function:

import numpy as np
from matplotlib import pyplot as plt
x = np.arange(-2, 2, 0.01) 
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('plot.png')
plt.show()

output_4_0

From this plot it seems that the function has one root, zero, on [-2, 2]. This root is also the only fixed point of the function in this interval.

dakota

My randomly generated function is:

e^{\cos(x)}\cos^3(x)

The following shows how my function is defined in Python as well as a sample computation:

In[1]: from numpy import exp, cos
       def f(x): return exp(cos(x))*(cos(x))**3
       f(1)
Out[1]: 0.27074520446733441

A plot of the function over the closed interval [-2, 2] is as follows:

 In[2]: %matplotlib inline
        from matplotlib import pyplot as plt
        import numpy as np
        x = np.linspace(-2,2,100)
        y = f(x)
        plt.plot(x,y)
        plt.plot(x,x)
        plt.savefig('graph.png')

my_pic

Looking at the plot, it appears that there are two roots on this interval and a fixed point around 0.75.

jorho85

My random function is:

f(x) = x^9(x^3 + e^{x^3})

In Python the function looks like:

from numpy import exp
def f(x): return x**9*(x**3 + exp(x**3))

I used this code to plot my function:

import numpy as np
from matplotlib import pyplot as plt
x = np.linspace(-2,2,100)
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.show()

Figure_1

The function is zero at x = 0, but finding the fixed points is difficult with this graph because the function explodes in value after x = 1 so I graphed the function over a smaller range of x values to get:

Figure_1-1

This shows there are two fixed points at x = 0 and another around x = 0.8.

pbahls

Here is my randomly generated function:

x^{3} + \sin{\left (x^{3} \right )} + \cos{\left (x^{3} \right )}

Here’s how I’d define it in Python:

from numpy import cos
def f(x):
  return x**3 + sin(x**3) + cos(x**3)

And here’s how I’d plot it over the desired range using matplotlib:

import numpy as np
from matplotlib import pyplot as plt
x = np.arange(-2, 2, 0.001) #xmin, xmax, stepsize
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('plot.png')
plt.show()

Here’s the resulting plot:

my_pic

It looks like there might be one root and one fixed point, quite close to that root.

Aisling

My randomly generated function is

f(x)=e^{\sin{\left (e^{x} \right )}} \sin{\left (e^{x} \right )}

The function in python is:

from numpy import sin, exp
def f(x): return exp(sin(exp(x)))*sin(exp(x))

To plot:

import numpy as np
from matplotlib import pyplot as plt
x = np.arange(-2, 4, 0.001) #xmin, xmax, stepsize
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('my_pic.png')
plt.show()

Producing,
my_pic
This shows that there are five fixed points and many roots.

theoldernoah

My randomly generated function is

x^{3} + e^{x} + \sin{\left (x^{3} \right )}.

I can define that and do a quick computation in Python like so:

from numpy import sin, exp
def f(x): return x**3 + exp(3)+sin(x**3)

I can plot my function as well:

%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
x = np.arange(-5,5,0.1)
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('my_pic.png')

Random Function Graph

Between -5 and 5, there appears to be one root and one fixed point, with the fixed point being somewhere around x = -3.

anonymous_user

My personalized function is

2 x^{3} + \cos{\left (x \right )}.

I can define this function in Python with the snippet

from numpy import sin, cos, exp
def f(x): return 2*x**3 + cos(x)

I can plot my function, along with the line y=x with

import numpy as np
from matplotlib import pyplot as plt
x = np.arange(-2, 2, 0.001)
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('timsplot.png')

timsplot

The graph shows a single fixed point at approximately - 0.91, and a single root at approximately -0.72.

Cornelius

My randomly generated function is:

f(x)=\cos^{2}{\left (x^{3} \right)}

We can define this function in Python like so:

from numpy import sin, cos, exp
def f(x): 
return cos(x**3)**2

Using Python to plot the function over the interval [2,2]:

import numpy as np 
from matplotlib import pyplot as plt
x=np.arange(-2,2,0.01)
y=f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('plot.png')
plt.show()

Numerical1
Looking at the plot it appears that there is only one fixed point in the given interval, and six roots.

Bara223

My random function is

\ f(x)= x^{3} e^{x} \sin{\left (e^{x} \right )}

In python, the code for the function is

  from numpy import exp, sin
  def f(x): return (x**3)exp(x)(sin(exp(x))) 

This is the code that graphs my function

import numpy as np
from matplotlib import pyplot as plt 
x = np.arange(-2, 2, 0.001)
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('plot.png')
plt.show()

Unknown

In the graph between -2 and 2 there are three roots and four fixed points

Sampson

My personalized random function is:

\left(e^{x} + \sin{\left (x \right )}\right) \sin{\left (x \right )}

Defining my function f(x) and doing a quick calulation:

from numpy import sin, exp
def f(x): return (exp(x)+sin(x))*sin(x)
f(1)

# Out: 2.9954287054524134 

Finally here is a bit of code to plot my function.

%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
x = np.linspace(-2,2,100)
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.savefig('Sam_pic.png')

MatheMagician

My function is:

f(x)=x^3 + x + 2*sin(x)

Python can define this function as:

from numpy import sin
def f(x):
return x**3 + x + 2*sin(x)'

This can be graphed by doing:

import numpy as np
from matplotlib import pyplot as plt
x=np.arange(-2,2,0.01)
y=f(x)
plt. plot(x,y)
plt.plot(x,x)
plt.savefig(‘plot.png’)
plt.show()

image

CestBeau

My randomly generated function is

f(x) = 2 \cos^{3}{\left (x \right )}

Which in python is written as follows,

import numpy as np
def f(x):  return (2*(np.cos(x))**3)

Finally we plot the function on the specified interval

%matplotlib inline 
from matplotlib import pyplot as plt
x = np.linspace(-2,2,100)
y = f(x)
plt.plot(x,y)
plt.plot(x,x)
plt.plot([-2,2],[0,0],lw=1)
plt.savefig('myfunction.png')

download

As evident in the image we have one fixed point and two roots on [-2,2], the roots can be seen through intersection with the green line y=0 and the fixed points through intersection with the orange line y=x.

mark

@CestBeau Looks great! Note, though, that I edited your reply so that the code looks like code. A block of code is indicated by simply indenting the code four spaces. If you start a line with a >, the following text is treated as a block quote, as in:

I recommend you to question all your beliefs, except that two and two make four.
– Voltaire, L’Homme aux quarante écus

funmanbobyjo

Using my student ID and the given code, I generated this equation:

f(x)=\left(x^{3} + e^{x^{3}}\right) e^{x}

This is how I defined the code in python and generated a sample computation:

  In [2]: from numpy import sin, cos, exp 
  def f(x): return (x**3+exp(x**3))*(exp(x))
  f(1)
  Out[2]: 10.107337927389695

To plot this the following was used

 ln[3]: %matplotlib inline
        from matplotlib import pyplot as plt
        import numpy as np
        x = np.linspace(-2,2,100)
        y = f(x)
        plt.plot(x,y)
        plt.plot(x,x)
        plt.savefig('my_pic.png')

to get this image:

I zoomed in by making th plot range from -2 to 1.2 to get the following:

So it seems like there is one root on the interval and no fixed points. (I’m unsure about this part, and I think there may be 2 or 3 roots)

bitchin_camero

My randomly generated equation was the equation f(x) = x^3 (x^4 + x^3)
using my student ID number and I generated it through

def f(x): return x**3*((x**4)+(x**3))
f(1)
Out[1]: 2

To plot this I used

%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
x = np.linspace(-1,1,100)
y = f(x)
plt.plot(x,y)
plt.plot(x,x)

plt.savefig(‘plot.png’)


There seem to be 2 fixed points, 1 at 0 and another around 0.85 or 0.9