For the following problems, you may use any programming language or choice. 2.7
ID: 3745400 • Letter: F
Question
For the following problems, you may use any programming language or choice. 2.7 PROGRAMMING PROBLEMS script of your This problem continues with Problem 2.17. The mechanism drawing in Problem 21 of 1" -2". Use the dimensions Programming Problem 1 2.17 has a scale 14.8", 2 2.0", and 6 3.65" The input has a value of 62 283° 4.94 radians. Use an initial guess at the solution of 3" 300° 5.2360 rad 300 5.2360 rad Print out the initial value of i0 given above, along with the new value of i that comes after each of five iterations through Newton's Method, as in Example 2.9. The program you write here will be used in the first programming problem 5 in Section 7.1, s0 save your code.Explanation / Answer
#include<bits/stdc++.h>
using namespace std;
//N-R method
//xn+1 = xn - f(xn)/f'(xn)
double f(double x){
//return function
//Enter your funtion here.
}
double df(double x){
//return d(funtion)
//Enter the derivative of the function here.
}
double next_value(double x){
return x - (f(x)/df(x));
}
//Driver Program
int main(){
double x0; //intial guess
double previous = x0; //Previous value
double next = x0; //Next value
double ans;
double itr = 5; //No. of Iterations
cout<<"Enter your initial guess: ";
cin>>x0;
for(int i=0;i<itr;i++){
previous = next;
next = next_value(previous);
cout<<setprecision(10);
cout<<"Iteration "<<i+1<<": "<<"Intial value: "<<previous<<"New Value: "<<next<<endl;
}
ans = next; //final answer
cout<<setprecision(10);
cout<<"Answer:"<<ans<<endl;
return 0;
}
//Note: For any query, please comment.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.