Optimization and root finding

Assignment Help C/C++ Programming
Reference no: EM131106209

V. ASSIGNMENT 1 - OPTIMIZATION AND ROOT FINDING Often in physics it is desirable to find optimum conditions and to find the roots of functions numerically. The aim of this assignment is to investigate a function f(x), which is given by the formula f(x) = sin(x a − x 1 a + ax) (2) where the constant a is different for everybody, so that everybody is exploring a unique function. If you write down your student number (e.g. 12345678) then the last four digits (e.g. 5678) will be used to determine the value of a. • the value of a is 0.4 + (digits 5678 together)/25000 • for example, with the student number 12345678, a = 0.4 + 5678 / 25000 = 0.4 + 0.22712 = .62712 Note that for this function it is necessary that x ≥ 0 because f(x) will give complex results for x < 0. A. Assignment tasks 1. Plot y = f(x). Write a program to calculate f(x) for a range of x values with x ≥ 0. A function should be used to evaluate f(x). The results should be saved in a file of the type x0 f(x0) x1 f(x1) x2 f(x2) ...etc. where f(x0), f(x1), f(x2) etc. are the values of the function evaluated at regularly spaced x values x0, x1, x2, etc.

The data should be read in with Excel and plotted on a graph. The graph should run from x = 0 where f(x) = 0 and have a long enough range so that the function crosses the x-axis two or three times at larger values of x. [40] 2. Write a program to find roots where f(x) = 0 with the Newton-Raphson method. The first root is x = 0. Use the program to find the next two roots for f(x) = 0. The approximate positions of these next two roots should be visible from the graph you plotted. More accurate values can be found with the Newton-Raphson method. For the Newton-Raphson method you will need f ′ (x) ≡ df(x) dx , which is given by f ′ (x) = A cos(x a − x 1 a + ax) (3) where A = axa−1 − 1 a x 1 a −1 + a (4) The program should write each step of the iteration to a file with output x0 f(x0) f ′ (x0) x1 f(x1) f ′ (x1) x2 f(x2) f ′ (x2) ...etc. where x0 is the chosen start value of x, and f(x0) and f ′ (x0) are values of the function and gradient evaluated with x0; x1 is the refined estimate calculated from x0, f(x0) and f ′ (x0), and so forth. [30] 3. Find the most accurate value you can for the first maximum of f(x). The simplest way to do this is to use the program written for the first part of this assignment and hunt for it with that. The neatest solution, however, will be to find the maximum by either using the Newton-Raphson method to minimize f ′ (x) and/or by using the method of bisection. [30] B. What should be handed in Both paper and electronic submission is required for this assignment

1.       Paper report A paper report should be handed in with the following key points covered for each task. 1. Plot y = f(x). • A figure to show the plot of the function • A table with a few lines of output from the program with values of x from 0 to 0.1 in steps of 0.01; viz., x f(x) 0 f(0) 0.01 f(0.01) 0.02 f(0.02) ...etc. 0.1 f(0.1) 2. Find roots where f(x) = 0 • Clearly labelled results to show the values of x found for the roots where f(x) = 0. • A table few lines from the output from the Newton-Raphson optimization program; viz., x f(x) f ′ (x) x0 f(x0) f ′ (x0) x1 f(x1) f ′ (x1) x2 f(x2) f ′ (x2) ...etc. • The result from your NewtonRaphson optimization program of starting from x = 2; viz., x f(x) f ′ (x) 2 f(2) f ′ (2) x1 f(x1) f ′ (x1) x2 f(x2) f ′ (x2) ...etc. and a comment about how successful this was in reaching a root where f(x) = 0 3. Find the first maximum of f(x) • Your best value for the maximum of f(x) • A description of the method that you used to find the maximum with samples of data. 4. Appendix 

 

• A copy of each program used should be in the appendix clearly labelled. 2. Electronic submission You should submit • Electronic copies of the programs used in this assignment. • An electronic copy of your paper report. • An electronic copy of the Excel workbook used to make the plot for the first part of the assignment. C. Hints and notes • Do put plenty of comments in your programs to explain what each part of each program does. • In the Newton-Raphson method xn+1 = xn − f(xn) f ′ (xn) (5) • The Bisection method is more complicated to program, but has the advantage that it is not necessary to know f ′ (x). If x0 < x1 < x2 and f(x1) > f(x0) and f(x1) > f(x2) then there must be a local maximum between x0 and x2. This is a generally true rule. The Bisection method commences with three equally spaced x values x0, x1and x2 which satisfy the rule above. Now, two new x values are determined; x3 is placed midway between x0 and x1, and x4 is place midway between x1 and x2. f(x3) and f(x4) are evaluated. There are now five adjacent points x0 < x3 < x1 < x4 < x2; three adjacent points are chosen which satisfy the rule above and these three points are taken as the new x0, x1and x2 values. The same procedure is repeated until, ultimately, the space between the three values becomes so small it is insignificant.

 

327_1.png


Attachment:- Physics_C_1.pdf

Reference no: EM131106209

Questions Cloud

Prepare the journal entry at the date of the bond issuance : (Entries for Bond Transactions) On January 1, 2010, Osborn Company sold 12% bonds having a maturity value of $800,000 for $860,651.79, which provides the bondholders with a 10% yield.
How old will each be when she becomes a millionaire : Kitty invested in the New Issue Bio-Tech Fund, which invests in small, newly issued bio-tech stocks and whose investors have earned an average of 20% per year in the fund's relatively short history. a. If the two women's funds earn the same returns i..
How much should you raise your product prices : you would have to borrow funds from your bank at a nominal 12%, daily compounding based on a 360-day year. You want to increase your base prices by exactly enough to offset your bank interest cost. To the closest whole percentage point, by how much s..
The payment of interest and the amortization of the premium : Will the bond interest expense reported in 2011 be the same as, greater than, or less than the amount that would be reported if the straight-line method of amortization were used?
Optimization and root finding : OPTIMIZATION AND ROOT FINDING Often in physics it is desirable to find optimum conditions and to find the roots of functions numerically. The aim of this assignment is to investigate a function f(x), which is given by the formula f(x) = sin(x a − x 1..
What apr rate should you charge your customers : To carry receivables, you must borrow funds from your bank at a nominal 6%, monthly compounding. To offset your overhead, you want to charge your customers an EAR (or EFF%) that is 2% more than the bank is charging you. What APR rate should you charg..
Based on the ear (or eff%), which bank should you use : Bank A pays 4% interest compounded annually on deposits, while Bank B pays 3.5% compounded daily. a. Based on the EAR (or EFF%), which bank should you use?
Chinook corporation incurred the following costs : Printing and engraving costs, $15,000; (2) legal fees, $49,000, and (3) commissions paid to underwriter, $60,000. What amount should be reported as Unamortized Bond Issue Costs, and where should this amount be reported on the balance sheet?
What is the most expensive car you can afford : You have saved $4,000 for a down payment on a new car. The largest monthly payment you can afford is $350. The loan will have a 12% APR based on end-of-month payments. What is the most expensive car you can afford if you finance it for 48 months? for..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write an iterative function power

Write an iterative function power1 to compute xn for n >= 0 and write a recursive function power2 to compute xn by using the following recursive formulation

  Each clone will communicate to the parent process

Write a program that will create 3 clones. Each clone will communicate to the parent process over a pipe (There are 3 pipes) Each process will write Process n.

  When constructors and destructors are called

Objects, constructors and destructors are called each time the objects Enter and leave scope and inherit parent class

  Write a version of the domino game

What is one thing that you did in this assignment that is similar to previous ones? Was it easier this time? How did you approach doing it? If you have any other thoughts about the assignment please write them here.

  Basics of code development on linux and cryptography

Prepare a C program that gives simple mono-alphabetic substitution between plaintext, and Enhance your code to use "-e" to encrypt a string argument and "-d" to decrypt it using argv and argc

  Requirements of flyhigh airlines

The development team of SoftSols Inc. has revamped the software according to the requirements of FlyHigh Airlines and is in the process of testing the software. While testing the software, the team encounters the following issues:

  Build a method for performing frequency analysis

Build a basic cipher base class that may be derived from for the ciphers and decode a Caesar Cipher text. You will have two cases.

  Give examples of pretest and posttest loops

Give examples of pretest and posttest loops - Discuss the syntax of while, for, and do...while loops. Give examples.

  Write a lexical analyzer which reads a c- program

Write a lexical analyzer which reads a C- program, strips off comments (denoted by /* comments */), and generates four symbol tablets.

  Definitions of the class circularlinkedlist

Write the definitions of the class circularLinkedList and its member functions. (You may assume that the elements of the circular linked list are in ascending order.)

  Program to print out invalid number to character

The integer must contain 3 distinct non-zero number, or the program will print out invalid number.it should print out invalid query.

  C++ program that reads in two positive integers

Write a C++ program that reads in two positive integers that are 20 or fewer digits in length and outputs the sum of the two numbers.

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