Question
Python Help(screen shot if you can)thx!
Consider the example found in the lecture notes: Example: A horizontal cantiever beam is subject to a uniform, vertical load.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#defining beam function
def beam_func(a):
return a**4 - 4*a**3 + 6*a**2 - 3*0.75

#increment search method
def roots(x0, h, N):
  
# initial values for starting the method
x1 = x0
f1 = beam_func(x1)
x2 = x0 + h
f2 = beam_func(x2)
i = 0
#checking for change in sign while iterating
while(f1*f2 > 0):
if(i > N):
print("Solution Not Found")
return None
  
x1 = x2
f1 = f2
#incrementing with the step h
x2 = x1 + h
f2 = beam_func(x2)
i = i + 1
  
#root is in between x1 and x2 so we take average for approximation
return (x1 + x2)/2
  
def main():
n = int(input('How many times to run increment search method: '))
i = 0
while(i < n):
#taking input
x0 = int(input('Enter x0: '))
h = float(input('Enter h: '))
N = int(input('Enter N: '))
#print only if solution found
if(roots(x0, h, N) != None):
print("%4.5f" %roots(x0, h, N))
i = i + 1

main()

SCREENSHOT

In [6]: #defining beam function def beam_func (a): return a**4 - 4*a**3 6*a**23*0.75 #increment search method def roots(xe, hdef main() n- int (inputHow many times to run increment search method:)) while(i n): #taking input xe- int (input( Enter xe:How many times to run increment search method: 3 Enter xe: 1 Enter h: -0.05 Enter N: 10 Solution: 0.82500 Enter xe: 3 Enter h

NOTE: Please take care of indentation while copying and pasting the code as the indentation is lost while pasting.

Please go though above code and comments and message me if you have any doubt.

Give me a thumbs up. Thanks.

Add a comment
Know the answer?
Add Answer to:
Python Help(screen shot if you can)thx! Consider the example found in the lecture notes: Example: A horizontal cantiever beam is subject to a uniform, vertical load. The beam extends from its...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT