Question

part 2 to the problem in matlabThe value of T can be estimated from the following equation: In your script file, estimate the value of t for any number of tthis is the hint that came with the problem

HINTS: Start by prompting the user to enter in a value for x and a tolerance (enforce that the tolerance is a correct value).

The value of T can be estimated from the following equation: In your script file, estimate the value of t for any number of terms. You must ask the user for the desired number of terms and calculate the absolute error/difference between your calculation and the built-in MATLAB value ofpi. Display your results with the following message (including the asterisks) where II is the number of terms used to calculate π, F . FFFFFFFFFF is your final result printed out with %f with 10 digits past the decimal point, and E. EEEEEEEE is the absolute error/difference between your calculation and pi printed out with %E with 8 digits past the decimal point. For 11 terms the estimated value of P1 = F. FFFFFFFFFF with an absolute difference of E.EEEEEEEE with pi in MATLAEB You may test your program with 5, 10, and 40 terms. HINT: Use a for loop to calculate the product above. Note that the numerator of term 1 is V2+0 and numerator of term 2 is /2 + numerator of term 1. This pattern is repeated for the rest of terms. Also, note that every numerator is divided by 2. The final value of pi can then be calculated from the completed product. It is strongly recommended that you use the in-class activities and lecture notes as a model for how to write your code.
HINTS: Start by prompting the user to enter in a value for x and a tolerance (enforce that the tolerance is a correct value). Then, write your while loop to estimate f(x) using the infinite series for a single x value, i.e. if x was a scalar, and the provided tolerance. Modify your while loop conditional to account for a maximum number of iterations. Test your code with x = -2 and a tolerance of IE-1, 1E-5, 1E-10. Check your answers with the value of (1x) exp (x) in MATLAB. Modify your code to estimate f(x) if x is a vector. This can be done by putting a for loop around your calculation for x as a scalar and iterating through each value of x in the vector one at a time to calculate the appropriate f(x) value. Test your code with x --3:3 and a tolerance of 1E-8. Check your answers with the value of (1 x) .* exp (x) in MATLAB. Modify your code one more time to estimate f(x) if x is a matrix. This can be done by adding one more for loop around your calculatation for x as a vector to iterate through each (row, column) element of your matrix to calculate the appropriate f(x) value. Test your code with x = [ 1 : 4 ; -4:-1 ; 7 : 10 ] and a tolerance of 1E-8. Check your answers with the value of (1+x) * exp (x) in MATLAB.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

n=input('enter the number of terms\n');
trueval=pi;
num(1)=sqrt(2);
deno=2;
x=num(1)/deno;
for i=2:n
num(i)=sqrt(2+num(i-1));
newx=x*num(i)/deno;
x=newx;
end
EPI=(1/x)*2;
err=abs(trueval-EPI);
fprintf('For %d terms the estimated value of PI=%.10f with an\n absolute error difference of %.8f with pi in MATLAB',n,EPI,err)

Command Window >noia enter the number of terms For 5 terms the estimated value of PI-3.1403311570 with an absolute error diff

Add a comment
Know the answer?
Add Answer to:
Part 2 to the problem in matlabthis is the hint that came with the problem
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is a matlab HW that I need the code for, if someone could help me figure this out it would b...

    This is a matlab HW that I need the code for, if someone could help me figure this out it would be appreciated. The value of t can be estimated from the following equation: in your script file, estimate the value of π for any number of terms. You must ask the user for the desired number of terms and calculate the absolute error/difference between your calculation and the built-in MATLAB value ofpi. Display your results with the following message...

  • MATLAB help! I have some MATLAB Assignment to do, the proffesor requires all the small parts...

    MATLAB help! I have some MATLAB Assignment to do, the proffesor requires all the small parts in order to get full credit. Help me out, thank you f LAB SECTION NAME HW6P3 (30 points) following are infinite series representations of the function, un pra i a script file HW6P3 that determines the value of the function from the sum of the series for a given value of x. The program (1 pt) must prompt the user to enter a value...

  • Programming Language: MATLAB Problem 3: (5 Points) Write a function with the header: function [R] -myNewtonRaphson...

    Programming Language: MATLAB Problem 3: (5 Points) Write a function with the header: function [R] -myNewtonRaphson (f, fp, x0, tol) which takes as input f: a function handle fp: a function handle to the derivative of f (note how I do it in the test case). x0: the initial guess of the root tol: a tolerance above which the algorithm will keep iterating. Tips: . Be sure to include an iteration counter which will stop the while-loop if the number...

  • Lab #2 Discrete-time Fourier Transform (DTFT) OBJECTIVES: • Explore the DTFT, its meanings and concepts. •...

    Lab #2 Discrete-time Fourier Transform (DTFT) OBJECTIVES: • Explore the DTFT, its meanings and concepts. • Get acquainted with Matlab/Octave 1) Start MATLAB and change the “Current Directory” in the top of the window (or type) >> cd '' (example: >> cd 'C:\NIU\lab2') Alternatively, if you don't want to use MATLAB, you can open a web-browser and go to “octave-online.net”. 2) Download and execute LAB2forStudent_A.M with >> lab2forStudent_A and observe that it produces a Discrete-Time (DT) signal xVec. 3) TO...

  • Calculation of the value of pi: The Nilakantha Series was developed in the 15th century as...

    Calculation of the value of pi: The Nilakantha Series was developed in the 15th century as a way to calculate the value of pi: pi = 3 + 4/(2*3*4) -4/(4*5*6) + 4/(6*7*8) -4/(8*9*10)+... . Use a for loop to approximate pi using this technique (5 points). Continue the calculations until the absolute value of the difference between the value of pi stored in MATLAB and the approximation is less than 0.001. Report the appproximation and the number of iterations required...

  • Rewrite the following for loop into a whileloop. 1 2 3 4 int s = 0;...

    Rewrite the following for loop into a whileloop. 1 2 3 4 int s = 0; for (int i = 1; i <= 10; i++) {    s = s + i; } Given variables int n and double pi, write a snippet of code that assigns to pi the approximation of π resulting from adding the first nterms in the Gregory-Leibniz series: Given variables int areaBound and int sum, write a snippet of code that assigns to sum the result...

  • Matlab Question 2. For this problem you have to create a program that defines two vectors...

    Matlab Question 2. For this problem you have to create a program that defines two vectors of numbers: A and B and uses a for-loop to combine the values of A and B. Note that different parts of the question below specify different orders for combining the elements. To start this exercise start a MATLAB script called q2.m and put, at the top, the vector definition: B [11:20] Question 2a: Problem definition Copy the file q2.m to q2a.m. For this...

  • Q3. Find the largest value of t > 0 such that on your computer system (a)...

    Q3. Find the largest value of t > 0 such that on your computer system (a) e'>0 (b) e' is a finite number The Matlab function exp gives the exponential function. Q4. Using integration by parts the integral J, = ſx"et-'dx can be evaluated as (1) Jo = e ', J, =1 – n.J =1 (1) Using Equation (1) calculate Jn for n=1, 2,...10 (a) with the approximate value e'= 0.367879. (b) with the value él = exp(-1) provided by...

  • Please let me know if you have any questions. Thanks in advance! We want to develop...

    Please let me know if you have any questions. Thanks in advance! We want to develop a code that calculates In(1 - x) =- on the interval -1<x<1. First, understand what this notation represents. The capital sigma (2) indicates that a summation of terms is to be performed. (The term summation still applies even though all the terms are negative.) We are also given the prototype term written in terms of x and n. The notation also tells us that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT