Ask C/C++ Expert


Home >> C/C++

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

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91859592
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As