
function [output] = Summation(n)
disp(['for n = ' num2str(n)])
sumI = 0;
while n>0
sumI = sumI + (((-1).^n*n.^2 + 5*n )/3.^n);
n=n-1;
end
output = sumI;
end
Summation(10)
Summation(20)
%--------------------------------------------
function [output] = Summation(n)
disp(['for n = ' num2str(n)])
sumI = 0;
for k=1:1:n
sumI = sumI + (((-1).^k*k.^2 + 5*k )/3.^k);
end
output = sumI;
end
Summation(10)
Summation(20)
Use a while-end loop in a script file to calculate the sum of the first n...
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
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;...
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 MATLAB script file that will sum all the positive entries in V and stop summing once the sum reaches or exceeds 20(while loop). An fprintf statement should be used to display the value for the sum to prove it has reached or exceeded 20, and the number of entries to reach this value should be displayed. V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7] Reminder: don’t use the built-in function, sum. Use...
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...
write matlab script
5. Use a for loop to sum the elements in x = [1 2 3 4 5] Check your answer with sum function 6. Use a while loop to sum the elements in x = [1 2 3 4 5] Check your answer with sum function
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)...
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!”.
Write a script (M file) to compute: S = sigma_n=1^15 n/n + 1 (a) using a for/end loop, but not array operators or sum. (b) using array operators and sum, but not any for/end loop What is the value of S?
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...