Write a program that demonstrates the least squares

Assignment Help Python Programming
Reference no: EM132807628

MAE 3403 Computer Methods in Analysis and Design - Oklahoma State University

Question 1) For this problem, we will re-work homework 2a using the integrate.gauss function of scipy.integrate rather than the Simpson method to find:

P(x<1|N(0,1)): probability x<1 given a normal distribution of x with μ=0, σ=1
P(x>μ+2σ|N(175, 3))

Rather than printing your findings to the console, we will use matplotlib.pyplotto produce nicely formatted plots such as shown below. Additional requirements are:
• You should put your main function in a file called HW4a.py and all other functions in a file called NumMethods.py.
• You should import your methods from NumMethods.py with the statement:
import NumMethods as nm in your HW4a file.
• You should use numpy arrays for all of your work on this problem where arrays are needed.

Note: code stems for HW4a.py and NumMethods.py are available for download.

1183_figure.jpg

Question 2) Write a program that demonstrates the Least Squares Curve Fitting method. You must write and call at least the following 3 functions:

def LeastSquares(x, y, power): #calculates and returns an array containing the coefficients of the least squares polynomial.

def PlotLeastSquares(x, y, power, showpoints=True, npoints=500): #calls LeastSquares, generates data points and plots the least squares curve. If showpoints is True, also put the original data on the same plot.

def main():

A main program that uses the data given below to:
1. Call LeastSquares to generate and print the coefficients of a Linear fit.
2. Call PlotLeastSquares to display a plot for the Linear fit
3. Call LeastSquares to generate and print the coefficients of a Cubic fit.
4. Call PlotLeastSqares to display a plot for the Cubic fit
5. Uses the results from 1 and 3 to plot the datapoints, the Linear fit and the Cubic fit, all on one graph. Use proper titles, labels and legends.

x=[0.05, 0.11, 0.15, 0.31, 0.46, 0.52, 0.70, 0.74, 0.82, 0.98, 1.17]
y=[0.956, 1.09, 1.332, 0.717, 0.771, 0.539, 0.378, 0.370, 0.306, 0.242, 0.104]

Note: a code stem for HW4b.py has been written and made available.

Question 3) Write a program that demonstrates the Cubic Spline Curve Fitting method. Youmust write and call at least the following 3 functions:

def CubicSpline(x, y, slope1=0, slope2=0): #calculates and returns a matrix containing the coefficients of the cubic splines. slope1 and slope2 are the slopes at the first and last points.

def PlotCubicSpline(x, y, slope1, slope2, showpoints=True, npoints=500): #calls CubicSpline, generates data points and plots the cubic spline curve. If showpoints is True, also put the original data on the same plot.

def main():

A main program that uses the data and slopes given below to:
1. Call CubicSpline to generate and print the coefficients.
2. Call PlotCubicSpline to display a plot of the natural and clamped cubic splines as shown below.

x=np.array([1.5, 3, 4.5, 6, 7.5, 9])
y=np.array([3.5, 1.5, -2, 6.9, 8.2 ,1.5])
slope1=2
slope2=-4

816_figure1.jpg


Notes: a code stem for HW4c.py has been made available. For a reminder of cubic spline interpolation, see the NumericalMethodsTutorial.docx.

Attachment:- SP21.rar

Reference no: EM132807628

Questions Cloud

How did the inflation rates move after the fed quantitative : How did the inflation rates move after the Fed's quantitative easing following the financial crisis of 2008? And how do you think about the impact of Fed
Corporate strategy-competitive strategy of mcdonalds canada : How the economic, legal and technological factors influenced the corporate strategy and competitive strategy of McDonalds Canada? Why? Support your answer.
Discusses various aspects of strategic planning : Discusses various aspects of strategic planning. As noted in the textbook, it is important to link performance management to strategy.
Propose an online recruitment and selection strategy : Propose an online recruitment and selection strategy that can improve Sodexo's process and satisfy the needs of its client in terms of qualified food workers.
Write a program that demonstrates the least squares : Write a program that demonstrates the Least Squares Curve Fitting method. You must write and call at least the following 3 functions
Did the authors construct scales in a clear : Were the authors' explanations clear regarding the reliability and validity of their measures? Did the authors construct scales in a clear, concise manner?
Qualitative research design : "Qualitative Research Design" and assess your dissertation proposal topic as suitable for qualitative exploration.
How the habit would be lived out in someone life today : What do the authors claim are the benefit of adopting these habits? Discuss how this habit would be lived out in someone's life today.
Passive communication styles to cement professional : How do you use assertive, aggressive, or passive communication styles to cement professional relationships with managers

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd