There's an error to this code when I run it in google collab  # objectives: 1) demonstrate numerical differentialtion, # and 2) illustrate results graphically. import numpy

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

There's an error to this code when I run it in google collab 

# objectives: 1) demonstrate numerical differentialtion,

# and 2) illustrate results graphically.

import numpy

import math

from numpy import arange, cos

import matplotlib.pyplot

from matplotlib.pyplot import *

# A general function for calculating the slope between two points: x and

# x+delta.

def der(x,delta):

    delta = float(delta)

    if delta < (0.0000001):

        print ('Value chosen for delta is too small.')

        return 1/delta

    else:

        slope = (f(x + delta) - f(x))/delta

        return slope

# Define the function y=100e^(-0.0482t)

def f(x):

    f = (100.0**(-0.0482*x))

return (f)

point = 2.0 #This is a point at which a derivative will be calculated.

# The following statements initialize variables for computation.

number = 510

increment =10

y = []

x = []

figure()

f=[3,-4,-12,0,2]

print ('\nFunction')

print (f)

print ('\nFirst Derivative')

g= f.deriv(m=1) # First derivative with m=1.

print (g)

print ('\nSecond Derivative')

q= f.deriv(m=2) # Second derivative with m=2.

print (q)


x=linspace(-2,3,101)

y=p(x)

yg=g(x) # These statements define points for plotting.

yq=q(x)

y0=0*x # This statement defines the y axis for plotting.

plot (x,y,label ='y=f(x)')

plot (x,yg,label ='First Derivative')

plot (x,yq,label ='Second Derivative')

legend(loc='best')

plot (x,y0)

xlabel('x-axis')

ylabel('y-axis')

title ('Plot Showing Function, First and Second Derivatives')

show()
title ('Plot Showing Function, First and second Derivatives'
show()
File "kipython-input-8-4f8c3bed2442>", line 41
return (f)
SyntaxError: 'return' outside function
SEARCH STACK OVERFLOW
Transcribed Image Text:title ('Plot Showing Function, First and second Derivatives' show() File "kipython-input-8-4f8c3bed2442>", line 41 return (f) SyntaxError: 'return' outside function SEARCH STACK OVERFLOW
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education