Question

Use a for-end / while-end loop in a script file to calculate the product of the...

Use a for-end / while-end loop in a script file to calculate the product of the first n terms of the series:

Execute the script file for n= 10 and n= 20.

Please use matLab

0 0
Add a comment Improve this question Transcribed image text
Answer #1
n = input("Enter value for n: ");
i = 1;
product = 1;
while i<=n
    product = product*i;
    i=i+1;
end
disp(product);

Output:

octave:5> source(TestCode.m) Enter value for n: > 10 3628800 octave: 6> source(TestCode.m) Enter value for n: > 20 2.4329

Note: Please comment below if you have any doubts. upuote the solution if it helped. Thanks!

Add a comment
Know the answer?
Add Answer to:
Use a for-end / while-end loop in a script file to calculate the product of the...
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
  • Use a while-end loop in a script file to calculate the sum of the first n...

    Use a while-end loop in a script file to calculate the sum of the first n terms of the series: sigma_k=1^n (-1)^kl^2 + 5k/3^k. Show the script file and the two results of n = 10 and n = 20. (b) Use a for-end loop in a script file to calculate the sum of the first n terms of the series: sigma_k=1^n (-1)^kl^2 + 5k/3^k. Show the script file and the two results of n = 10 and n =...

  • USE FOR LOOP INSTEAD OF WHILE LOOP Consider the following script file. Fill in the lines...

    USE FOR LOOP INSTEAD OF WHILE LOOP Consider the following script file. Fill in the lines of the following table with the values that would be displayed immediately after the while statement if you ran the script file. Write in the values the variables have each time the while statement is executed. You might need more or fewer lines in the table. Then type in the file, and run it to check your answers. k = 1; b = -2;...

  • Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to...

    Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to symbolically compute the derivative of ln(x) on the interval from -5 to 5, containing 100 data points. Your script file should output a plot of the derivative of ln(x) (taken from your function) vs x. Use a line with circular markers for the plot and include a grid and appropriate labels. The user-defined function should 1. Receive a single x value as input. 2....

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

  •        Write a shell script “6-1.sh” to calculate the exponentiation using while loop. This script needs...

           Write a shell script “6-1.sh” to calculate the exponentiation using while loop. This script needs to take two inputs like “6-1.sh a b”, and outputs the result of “ab”. Note: You need to implement it, DO NOT use the exponentiation operation provided by the Linux.        Write a shell script “6-2.sh” to calculate the factorial of a number using while loop. This script needs to take one input like “6-2.sh a”, and outputs the result of “a!”.

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

  • please help, this is so urgent, multiple question 14 14. After executing the following script file...

    please help, this is so urgent, multiple question 14 14. After executing the following script file in MATLAB X1 = [1 0 2; -1 50; 0 3 -9]; Xinvi= inv(x1); Xinvinv= Xinv2*X2 the displayed result is a b. 0.0000 0 0 0.0000 -0.0000 0.0000 -0.0000 -0.0000 0.0000 b. error c. 03 -9 -150 102 d. 1.0000 0.0000 -0.0000 0 1.0000 0.0000 0 -0.0000 1.0000 e. none of above 15. After executing the following script file in MATLAB a =17; while...

  • Solve using Matlab Write a simple loop to list the squares of the first 10 integers....

    Solve using Matlab Write a simple loop to list the squares of the first 10 integers. Using a simple "while" loop, write a script to sum the series 1 + 2 + 3 + ... such that the sum is as large as possible without exceeding 100. The program should display how many terms are used in the sum. Write a script that takes as input an integer n and creates the n*n matrix A with (ij)th component given by...

  • run/call tle un/cd to compute the sum of the first 15 terms of the series: th (b) It is desired 14 n3 - 20 n2 + 5n, 110) 1,2,..15 n Develop a pseudocode of the required program. roposed algorithm in...

    run/call tle un/cd to compute the sum of the first 15 terms of the series: th (b) It is desired 14 n3 - 20 n2 + 5n, 110) 1,2,..15 n Develop a pseudocode of the required program. roposed algorithm in a flow chart if it is solved using a for loop ow the p () Write a MATLAB script file using for loop run/call tle un/cd to compute the sum of the first 15 terms of the series: th (b)...

  • Using MATLAB code only please! 4. Write a script which does the following (use a while...

    Using MATLAB code only please! 4. Write a script which does the following (use a while loop). a. Creates a random number b. Calculates the sum of random numbers selected, across all loop iterations c. Prints the number of random numbers (the number of loop iterations) which were required to add up to 20 (or more).

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