Question

ale boh th Blac Your job is to draw exercise making sure that the flowchart is correspondent to the MATLAB code given. That m matlab only
0 0
Add a comment Improve this question Transcribed image text
Answer #1

% MATLAB code

i=1; % iteration variable
index = 1; % array index variable. Cannot be same as iteration variable since in some iterations conditions won't be satisfied
% to enter value in array, and that index in array would not be created giving rise to error in next iteration.

while (1) %infinite while loop
if index==1 % check condition for first element of array
x(index) =0;
index = index+1;
else
number = randn(1); % generate a random number
  if (number>=0 && number <0.5) % condition as given in question
x(index) = x(index-1)+1;
index = index+1;
elseif (number>0.5 && number <=1)
   x(index) = x(index-1)-0.5;
   index = index+1;
end
end

if index>=6 % check if array length is at least 6; if yes, check last 6 elements of array are positive
if(x(index-1) >0 && x(index-2) >0 && x(index-3) >0 && x(index-4) >0 && x(index-5) >0 && (index-6)>0)
break; % come out of while loop if last 6 values in array are positive
end
end

if i>=50
break; % come out of while loop for 50 or more iterations
end

i=i+1;
end

Add a comment
Know the answer?
Add Answer to:
Ale boh th Blac Your job is to draw exercise making sure that the flowchart is correspondent to t...
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
  • 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...

  • The function should starts as: function [x,fs,k]=Newton1(x0) % enter your code here end >> ...

    The function should starts as: function [x,fs,k]=Newton1(x0) % enter your code here end >> [x,f,k]=Newton1(0)  x = 1.1641, f = -1.6653e-16, k = 7 >> [x,f,k]=Newton1(0.1)  x = 0.1972, f = 1.1102e-16, k = 5 >> [x,f,k]=Newton1(1.5)  x = 1.3111, f = -1.1102e-16, k = 6 >> [x,f,k]=Newton1(2)  Warning iteration diverged, x = 2.8808, f = -0.5624, k = 1000 Let the mathematical function f(x) be defined as: f(x) = exp(-0.5x) cos(5x)-0.5 , x 〉 0...

  • Let the mathematical function f(x) be defined as: f(x) = exp(-0.5x) cos(5x)-0.5 , x 〉 0 Write a ...

    Let the mathematical function f(x) be defined as: f(x) = exp(-0.5x) cos(5x)-0.5 , x 〉 0 Write a Matlab function called Newton1 that would find the zero based on a passing initial guess as an input argument x0. The function returns the estimated zero location x, the function value at the zero location (f) and the number of iteration k. The iteration function converges if f(%) < 5*eps and it should diverge if the iteration number k>10000. When it diverges,...

  • clearvars close all clc tol = 0.0001; % this is the tolerance for root identification xold...

    clearvars close all clc tol = 0.0001; % this is the tolerance for root identification xold = 0.5; % this is the initial guess test = 1; % this simply ensures we have a test value to enter the loop below. %If we don't preallocate this, MATLAB will error when it trys to start the %while loop below k = 1; %this is the iteration counter. Similar to "test" we need to preallocate it %to allow the while loop to...

  • Programming Assignment 3 CSCI 251, Fall 2015 Infinite Series Trigonometric and math functions are...

    Programming Assignment 3 CSCI 251, Fall 2015 Infinite Series Trigonometric and math functions are usually calculated on computers using truncated Taylor series (an infinite series). An infinite series is an infinite set of terms whose sum is a particular function or expression. For example, the infinite series used to evaluate the natural log of a number is (x - 1)2 (x-1)3 (x-1)* (x-1)5 2 4 where x E (0, 2], or 0

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values...

    Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values for sin-1(x) from your program to those given by the Excel spreadsheet function ASIN(x). The Maclaurin arcsine expansion is given by x 3x 6 40 (2n)! sin1(x)-2((2n+1) Note: This function by definition is only defined for-1 SxS1. When you write the code for calculating it, you will need to include code that assigns a value to it that reflects it is undefined for values...

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...

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

  • Exercise #1: Write a C program that contains the following steps (make sure all variables are...

    Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. Commenting out the existing coding, write the code to divide a...

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