Question

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 t

The following are infinite series representations of the function n+ 1 f(x) (1 + x) ex- n=0 in your script file, estimate f(x

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 (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. rwer %; 鼎鼎鼎鼎鼎鼎鼎 For II terms the estimated value of PI -F. FFFFFFFFFF with an absolute difference of E.EEEEEEEE with pi in MATLAB 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 2+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.
The following are infinite series representations of the function n+ 1 f(x) (1 + x) ex- n=0 in your script file, estimate f(x) using the infinite series for a given value(s) of X. You must prompt the user to enter the value(s) of x; x may be entered as a scalar, vector or matrix. Use the factorial function to calculate n!. You must estimate f(x) for each value in x using a while loop that computes the sum until the absolute value of the nth term is less than a user defined tolerance, i.e. your program must prompt the user for a tolerance, or a maximum number of 50 iterations has been reached If the user enters in a tolerance outside of the range [0, 10E-2], you must print out the following message and re-ask the user repeatedly until they enter in an appropriate tolerance value Invalid entry, please re-enter a tolerance If the maximum number of iterations was reached for a given x value, the following message must be displayed The allowable number of iterations has been exceeded. If x is a scalar, display the final result with the following message where XX indicates where numbers should be placed. You may use the isscalar function to determine if x is a scalar. In XX iterations, the final result of (1 + X.xx) *exp (X. XX) is: XX.XX If x is an array, display the final result with the following message where x.xxx indicates the values stored inside the final result. Final result of (1 x) *exp (x) is:
0 0
Add a comment Improve this question Transcribed image text
Answer #1

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU

ANSWER:

CODE:

format long
inp2 = input('Enter the number of terms : ','s');
m = str2double(inp2);
t = 0;
s = 1;

for i = 1:m
for j = 1:i
t = sqrt(2 + t);
end
s = s * (t / 2);
t = 0;
end
s = 2 / s;
disp(s);

>>genPi Enter the number of terms 5 3.140331156954753 >>genPi Enter the number of terms 10 3.141591421511200 >>genPi Enter th

THANKS

OR

CODE:

clc
clear all
n=input('enter the valus of terms you need i.e n :'); % getting input for number of function from opeartor

for i=2:n
x(1)=(sqrt(2)); %defining first term without condsidering 2
x(i)=(sqrt(2+x(i-1))); %getting all numerator for (2/pi) as subject of equation
end
for i=1:n
x(i)=(x(i))/2;   
y(i)=(1/x(i)); %here we shall make pi as subject of our equation so we shall get eqm for (pi/2)
end
for i=1:n %loop for product of all numbers
if i==1
diff_pi(1)=y(1);
else
diff_pi(i)=y(i)*diff_pi(i-1);
end
end
absdiff= (pi)-2*diff_pi(n); %required answer
Diff_pi=2*diff_pi(n); %required answer   
fprintf('***************************************************\n');
fprintf('for %1f terms the estimeted value of PI = %1.10f with\n',n,Diff_pi);
fprintf('an absolute differnce of %1.8f with pi in MATLAB\n',absdiff);

Add a comment
Know the answer?
Add Answer to:
This is a matlab HW that I need the code for, if someone could help me figure this out it would b...
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
  • Part 2 to the problem in matlabthis is the hint that came with the problem

    part 2 to the problem in matlabthis is the hint that came with the problem 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...

  • 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...

  • This exercise is also from C++ How do I even figure this out? please help me...

    This exercise is also from C++ How do I even figure this out? please help me solve so I can get the answer correctly! Question 28 10 pts (SHORT ANSWER) Define a function named findEvenOrOdd that has 1 int parameter: num. When the function is called, it should use an if/else statement -OR- conditional expression to determine whether the variable num is an even or odd number and display appropriate message as follows: • If the value in num is...

  • Matlab Help I understand and already did 2a. Need help with the Matlab part (2b). 2....

    Matlab Help I understand and already did 2a. Need help with the Matlab part (2b). 2. (15 points) The Maclaurin series expansion of sin(x) is given by 3 sin)39 estimate the true value of sin(T/3). Calculate the truncation error (true percent relative error). (error between current and previous estimate) falls below 0.01%. Document the final value, the (a) Use the first three terms in this equation to calculate the value of sin(T/3). Use your calculator to (b) Now write a...

  • i need the answer to be on a MatLab window 1. Consider the following equation, which...

    i need the answer to be on a MatLab window 1. Consider the following equation, which represents the concentration (c, in mg/ml) of a drug in the bloodstream over time (t, in seconds). Assume we are interested in a concentration of c2 mg/ml C3te-0.4t A. Estimate the times at which the concentration is 2 mg/ml using a graphical method Be sure to show your plot(s). Hint: There are 2 real solutions B. Use MATLAB to apply the secant method (e.g....

  • matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name...

    matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name the function [max_value, max_index] - LASTNAMES matrix max (x), where input argument x is a vector or matrix (not a scalar), and the outputs are the maximum value(s) and indexes of the maximum value(s) of the mput x. Do not use MATLAB functions max() or find(). Use loops and if branches to determine the maximum elements of matrix. Check for correct number and valid...

  • Use the following pseudocode for the Newton-Raphson method to write MATLAB code to approximate the cube...

    Use the following pseudocode for the Newton-Raphson method to write MATLAB code to approximate the cube root (a)1/3 of a given number a with accuracy roughly within 10-8 using x0 = a/2. Use at most 100 iterations. Explain steps by commenting on them. Use f(x) = x3 − a. Choose a = 2 + w, where w = 3 Algorithm : Newton-Raphson Iteration Input: f(x)=x3−a, x0 =a/2, tolerance 10-8, maximum number of iterations100 Output: an approximation (a)1/3 within 10-8 or...

  • II. Using Newton’s method, write a MATLAB program to find the fixed point of the following...

    II. Using Newton’s method, write a MATLAB program to find the fixed point of the following function: ?(?) = √? + ?? accurate to at least 8 decimal places. (HINT: finding the fixed point of f(x) is the same as finding the zero of g(x) = f(x) − x. ) The output of this program should display in a single table (i) the solution for the fixed point, (ii) the initial guess, (iii) the number of iterations it took to...

  • Help with SIMULINK of Matlab: I want to put the transfer function,, but how do I...

    Help with SIMULINK of Matlab: I want to put the transfer function,, but how do I put function 2, so that it comes out as well as the original function, what should I put in the numerator and denominator? .. I know that I cannot use the constant (s) in the block, for that reason I find it difficult to put that equation in the block and the program works for me! PLease, write clearly the final answer for numerator...

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