Question

THIS IS USING MATLAB

1. The value of a can be approximated by: a. Write a script which asks the user to input the number of iterations (n), then c

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a) matlab script

============================================================================================

n=input('Enter number of iterations: ');
format long

temp=0;
%for lopp
for k=1:n
temp=temp+(1/k^2);
end

piValue=sqrt(6*temp);

fprintf('Value of pi using %d iterations is %.8f\n',n,piValue);

============================================================================================

Output

MATLAB R2018a 0 - Search Documentation X Login HOME AFFS PUBISH V EW SGG PLOTS Find File: Compare Print 5 New EDITOR Insert C============================================================================================

format long


%for loop
for n=1000:1000:10000
temp=0;
for k=1:n
temp=temp+(1/k^2);
end
piValue=sqrt(6*temp);
fprintf('n = %d,approx = %.8f\n',n,piValue);
end

============================================================================================

Output

MATLAB R2018a 0 - Search Documentation X Login HOME AFFS PUBISH V EW G G SS PLOTS Find File: Compare Print 5 New EDITOR Inser

Add a comment
Know the answer?
Add Answer to:
THIS IS USING MATLAB 1. The value of a can be approximated by: a. Write a...
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
  • Please complete using matlab In this problem you will utilize a for loop to compute the...

    Please complete using matlab In this problem you will utilize a for loop to compute the an approximation of the value of using the Leibniz's formula for Pi. The formula uses a summation. Follow the instructions correctly and read the questions thoroughly. 1. Set up the initial number of iteration i to obtain six iterations. 2. The approximate value of it can be given by the following formula: Approximated = Enzo 2n+1 Where n is an integer starting at zero...

  • Write a MATLAB code to compute the summation of the integers from 1 to 1000 by...

    Write a MATLAB code to compute the summation of the integers from 1 to 1000 by using for-end loop command. Your code should display the value of the summation within the following statement (using fprintf command): The value of the summation of the integers from 1 to 1000 is ???.

  • THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...

    THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such...

  • Write a MATLAB script, which asks the user to input the angle xd (in deg) and...

    Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylor's equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number,...

  • Self-check exercise: While-loops The value of (π^2)/8 can be approximated by the series Write a script...

    Self-check exercise: While-loops The value of (π^2)/8 can be approximated by the series Write a script that evaluates this expression, ignoring all terms that are strictly smaller than .000001. Your script should display the number of terms summed and the sum. Use a while-loop. Think about the initialization of your variables and the order of computation carefully! In the loop body you need to calculate the value of a term only once. We use the above series for approximating (π^2)/8...

  • [MATLAB Coding] A four-bar linkage system is shown above. The first link, a, is an input link (crank) of length 1. The second link, b, is a coupler link of length 2. The third link, c, is an output l...

    [MATLAB Coding] A four-bar linkage system is shown above. The first link, a, is an input link (crank) of length 1. The second link, b, is a coupler link of length 2. The third link, c, is an output link of length 4. The forth link, d, is the fixed link (ground) of length 5. All lengths are provided in metres. Please answer the whole question in MATLAB coding. 4 A four-bar linkage system is shown above. The first link,...

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

  • 3. Cosine Approximation Write a function m-file to calculate the approximated cosine function which can be...

    3. Cosine Approximation Write a function m-file to calculate the approximated cosine function which can be evaluated by the following infinite series - equation (2): 1. x² x4 26 (-1)(n+1). 22(n-1) cos x = 1 - 3 + - 6! + + (2(n − 1))! Here are requirements for the function m-file. - Parameter lists (inputs): 2 value (in radian), and desired error percentagel. - Return value (outputs): approximated value, real error percentage, and number of iterations - Function name:...

  • BME 2013 Spring 2019 Exam 3 Matlab Review Sheet 1. Given the vector of patient body temperatures ...

    can anyone help me figure out how fo write matlab code for these problems? BME 2013 Spring 2019 Exam 3 Matlab Review Sheet 1. Given the vector of patient body temperatures T (98.6, 102, 101, 99,98.9, 102.1, 100.3, 101.2, 98.4 97.6, 100] use conditional statements and loops to write a program that determines and displays (using the fprintf function) the number of patients with a fever and patients without a fever. The program must ask the user to input the...

  • In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +... cos(x)=1-1...

    In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +... cos(x)=1-1 2! 4! 6! Which can be expressed compactly as cos(x) = {(-1)+7 (2(k-1))! 00 2(k-1) k-1 Write Matlab code using a while loop that calculates cos(2) with 5 terms of Maclaurin series. Compare the value with the one calculated with a built-in function cos (2) in Matlab. The following is an expected output from your code: Using the Maclaurin series cos( 2.0) with 5...

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