Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using MatLab. Part of an introductory MATLAB class, I\'m just having a little di

ID: 3143442 • Letter: U

Question

Using MatLab.

Part of an introductory MATLAB class, I'm just having a little difficulty constructing loops correctly.

Thanks in advance.

Exercise 4 Write a script to do the followings: Prompt users to enter a value from 4 to 10 inclusive for S times Every time the user enters a value, display the value with appropriate message If the entered value if out of range or invalid, display a message to inform users and that round is not counted When all 5 valid values have been entered, display the Fibonacci sequence of the values, which is found by adding the two numbers before it together

Explanation / Answer

I'm not much familiar with syntax of MATLAB but as you need help in just loop so i think i can help you

We construct loop like this:

START
int a[5]; /* array for storing user input as a[0], a[1], a[2], a[3], a[4]*/
int F[5]; /* array for storing fibonacci sequence */
int x=0;    /* variable for taking user input*/
int i=0;    /* variable for counting number of inputs*/


While(i<5)
   {
   display_message( Please Enter any integer numbers from 4 to 10 inclusive.);
   x=(take input);
   if(x<4 or x>10)
       {
       display_message( Out of range or Invalid Input);
       }
   else
       {
       a[i]=x;
       i=i+1;
       }
   }
F[0]=x[0];
F[1]=x[1];
F[2]=x[0]+x[1];
F[3]=x[1]+x[2];
F[4]=x[2]+x[3];

display_message( Your input numbers are:);
   (display a[0], a[1], a[2], a[3], a[4])
display_message( Fibonacci sequence of input numbers is:);
   (display F[0], F[1], F[2], F[3], F[4])
END