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

  Create a text adventure game that uses pointers

Create a text adventure game that uses pointers. You have a rich, eccentric Uncle Billy who is soon to be deceased.

  Write a program which allows the user to perform simple task

Write a program which allows the user to perform simple tasks on a calculator. A series of functions allows the user to select an operation to perform and then enter operands.

  Static field holds total winnings for all horses in stable

static field holds total winnings for all horses in the stable // total winnings are shown after each horse wins,

  Implement a append function

Write and test the following function: void append(int a[], int m, int b[], int n); The function appends the first n elements of the array b onto the end of the first m elements of the array a.

  Program that displays the approximate number of customers

Write a program that displays the approximate number of customers in the survey who purchase one or more energy drinks per week.

  Run the program and explain the results

Run the program and explain the results. Rewrite the same code in C++ and Java and compare the results.

  Prompt the user for 3 sentences of text

Prompt the user for 3 sentences of text. Pass these pieces of text into a function connect() which will connect all three sentences into one long sentence. Pass the combination sentence back to the main program, where it is printed.

  Implement a class that can be used to keep track

Specify, design, and implement a class that can be used to keep track of position of a point in three-dimensional space. For example consider the point drawn at the topof the next coloumn. The point shown there has three coordinates;

  Write a recursive function

Write a recursive function, vowels, that returns the number of vowels in a string and write the definitions of the functions to overload the operators defined in parts a to c.

  Calculate the following integer quantaties

For example, July 31, 1929 gives a = 5, b = 31, c = 29, d = 19; January 3, 1988 gives a = 11, b = 3, c = 87, d = 19. Noe calculate the following integer quantaties

  Binary tree, print right view of it

Given a Binary Tree, print Right view of it. Right view of a Binary Tree is set of nodes visible when tree is visited from Right side.

  Write a function named totamt

Write a function named totamt() that uses four parameters named quarters, dimes, nickels, and pennies, which represent the number of each of these coins in a piggybank.

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