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

Write a python code that calculates π using numpy rand function.
Write a python code that calculates π using numpy rand function.
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
need to write program on python, without using any other libraries like panda, numpy, etc. here...
need to write program on python, without using any other libraries like panda, numpy, etc. here is google link on csv file https://drive.google.com/file/d/1O3cC9JAPVkXSrddTR6RocpSV8NMHrmRx/view?usp=sharing There is a csv file, which is exel file, very big and what program should do: - Read a CSV file 'annual.csv' enterprise into a data structure - Count the number of rows and columns - Determine if the data contains empty values (should search in all rows) - Replace the empty values by 'NA' for strings,...
I need the following problem to be coded in python without using Numpy: Given input features...
I need the following problem to be coded in python without using Numpy: Given input features x1​, x2​,..., xi​ and corresponding weights w0​, w1​, w2​,...wi​. Write a function, called 'Perceptron', that returns the output value yi. For your function, use the following perceptron activation function: g(X,W)={1 if wTx>0;0 otherwise} The inputs X and W will be arrays of the input feature and weight values, respectively. All values will be integers. Your function will return gp​(X,W), which is a single integer...
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"...
inverse a matrix using pseudo inverse using python (numpy can be used) for a 2d list...
inverse a matrix using pseudo inverse using python (numpy can be used) for a 2d list (n x n).
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT