Question

Write a function for Euler methods with python. Then find and write a test to prove...

Write a function for Euler methods with python. Then find and write a test to prove the code is right.

Homework Answers

Answer #1

# Following is a Python Program to find approximation of
# an ordinary differential equation
# using Euler method.
# Let us Consider a differential equation
# dy / dx =(x + y + xy)
def func( x, y ):
return (x + y + x * y)
  
# Function for Euler Expression
def Euler( x0, y, h, x ):
temp = -0
  
# Scanning till that point where we need approximation
while x0 < x:
temp = y
y = y + h * func(x0, y)
x0 = x0 + h
  
# Now Displaying Approximation
print("Approximate solution at x = ", x, " is ", "%.6f"% y)
  
# Driver Code to test
x0 = 0
y0 = 1
h = 0.025
  
# Value of x where we need approximation
x = 0.1
  
Euler(x0, y0, h, x)

OUTPUT:

Know the answer?
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
Similar Questions
In python write a function
In python write a function
python code Write the function definition for a function which accepts one value from the main...
python code Write the function definition for a function which accepts one value from the main program and prints three times the number that is sent to it. For example, if the program sent 8, the function would print 24.
How to write a Python program that has a base class with methods and attributes ,...
How to write a Python program that has a base class with methods and attributes , subclasses with methods and attributes. Please use any example you'd like.
Please write the python code for a function called called count_all_words that takes a phrase as...
Please write the python code for a function called called count_all_words that takes a phrase as an argument and counts each unique word in the phrase. The function should return a list of lists, where each sub-list is a unique [word, count] pair. (See example below.) Hint: A well-written list comprehension can solve this in a single line of code, but this approach is not required.
This is an intro to Python question: #Write a function called linear() that takes two parameters...
This is an intro to Python question: #Write a function called linear() that takes two parameters #- a list of strings and a string. Write this function so #that it returns the first index at which the string is #found within the list if the string is found, or False if #it is not found. You do not need to worry about searching #for the search string inside the individual strings within #the list: for example, linear(["bobby", "fred"], "bob") #should...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
Hello! I am confused on the code for this question. Write a complete Python function called...
Hello! I am confused on the code for this question. Write a complete Python function called Frog, with two integer parameters M and N, where N has the default value of 5. The function computes and returns one of two results: if N is odd it returns the equation 2 * M + N, but if it is even it returns the equation 3 * M - N instead.
Write a python code that will ask the user to enter an integer number n. Construct...
Write a python code that will ask the user to enter an integer number n. Construct a recursive function that prints numbers 1 to n in the form “11223344..nn”.
Python: Working with CSV file --> How would I write a function that will return a...
Python: Working with CSV file --> How would I write a function that will return a list of lists, with the frequency and the zip code. Organize the list in decreasing order of frequency (Print the number of suppliers and the zip code for the 10 most common zip codes in the file. ) An example of three items from the 720 zip codes results in: [ ... [9, '65616'], [8, '94573'], [8, '63103'] ...]. This tells us that Branson,...
PYTHON: Write a function that takes in a number as a parameter and calculates the square...
PYTHON: Write a function that takes in a number as a parameter and calculates the square of the number up to and including the value of the parameter. The function must perform the process recursively.