Question

In: Computer Science

Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x...

Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x + 4.

Solutions

Expert Solution

B = input('please enter the polynomial of B in the form ( 3x**3 + -5x**4 + 30) : ')
while '+' in B :
   index = B.index('+')
   B = B.replace('+' , ' ' )
B = B.split()
B_drv = []
def deriv(B):
    for parameter in B :
        if 'x' in parameter :
            index_y = parameter.index('x')
            multiply = parameter[0:index_y]
            # multiply referes to the number multiplied by 'y' , which is '9' in '9y**2'
            if multiply == '' :
                multiply = '1' #in case the user wrote 'y**3' instead of '1y**3'
            power = parameter[index_y+3:]
            # power referes to the power of 'y' , which is '2' in '9y**2'
            if power != '0' :
                drv_parameter = str(float(multiply) * float(power)) + 'x**' + str(float(power)-1) 
            else :
                drv_parameter = str(0) #in case the user wrote a parameter '4y**0' instead of '4'
            B_drv.append(drv_parameter) #filling the list
        else: #if there is no 'y' in the parameter
            drv_parameter = str(0)
            B_drv.append(drv_parameter)
    result = ' + '.join(B_drv) #for display
    return result

print ('The derivative of B is : ' + deriv(B))

Please upvote and comment incase of doubts


Related Solutions

Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python...
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python Script (ie n=user input) Ask (user input ) and (randomly generated) row and column location Assign Q to (known row and column location ) and 0 to all others location Please show compile script working as well
For these of string functions, write the code for it in C++ or Python (without using...
For these of string functions, write the code for it in C++ or Python (without using any of thatlanguage's built-in functions) You may assume there is a function to convert Small string into the language string type and a function to convert your language's string type back to Small string type. 1. int [] searchA,ll(string in...str, string sub): returns an array of positions of sub in in...str or an one element array with -1 if sub doesn't exist in in...str
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep...
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep to tell whether the participant are of the ages through 18 to 60 and sleep less than 6 hours per day? 2. Develop codes to check whether the sleep function you defined can make correct judgement. Make sure you write comments or create informative vairable name so that I can understand how you check the sleep function. (Hints: You can create toy data/dataframe to...
#Python program using loop instead of numpy or pandas. Write a function to enter n student...
#Python program using loop instead of numpy or pandas. Write a function to enter n student scores from 0 to 100 to represent student score, Count how many A (100 - 90), B(89-80), C(79-70), D(69-60), F(<60) We will use numpy array OR pandas later for this problem, for now use loop Invoke the function with 10 student scores, show the result as follow: Test Enter 10 scores Enter a student score: 99 Enter a student score: 88 Enter a student...
Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
Write a program in python that implements quicksort, first using recursion and then without recursion.
Write a program in python that implements quicksort, first using recursion and then without recursion.
"PYTHON" Write some code " USING PYTHON" to keep reading numbers from the user until the...
"PYTHON" Write some code " USING PYTHON" to keep reading numbers from the user until the users enters a negative number. The program then prints out: a) the sum of all the numbers b) the average of all the numbers c) the max of the numbers d) the min of the numbers Note we did not cover lists (array) so you will not use them in this problem. Finally, ask the user for their name, then print their name as...
(Python) a) Using the the code below write a function that takes the list xs as...
(Python) a) Using the the code below write a function that takes the list xs as input, divides it into nss = ns/nrs chunks (where nrs is an integer input parameter), computes the mean and standard deviation s (square root of the variance) of the numbers in each chunk and saves them in two lists of length nss and return these upon finishing. Hint: list slicing capabilities can be useful in implementing this function. from random import random as rnd...
Write a python function (Without using external libraries) to calculate the 1). determinate of a 2...
Write a python function (Without using external libraries) to calculate the 1). determinate of a 2 x 2 matrix 2). Calculate the inverse of a 2 x 2 matrix.
Consider the polynomial f(x) = 3x 3 + 5x 2 − 58x − 40. Using MATLAB....
Consider the polynomial f(x) = 3x 3 + 5x 2 − 58x − 40. Using MATLAB. Find the three roots of the polynomial, i.e, x where f(x) = 0, using Newton’s method. Report the number of iterations taken by each algorithm using a tolerance of 10−8 .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT