statement to determine if this number is even. If it is even use disp to say so ("The number 4 is even."), and if not, say that the number is odd. Hint: The function mod is the key to writing this if statement. Having remainder 0 when divided by 2 means that a number is even. 4. For loops: The Fibonacci numbers are a common concept in mathematics, and they are easily generated using a for loop. Write a loop to generate the first 20 Fibonacci numbers and store them all in an array. After you are done, display the array. The Fibonacci numbers F, are defined by F₁1 MATLAB ASSIGNMENT F₂ = 1 Fn = Fn-1 + Fn-2 so that at each step, you need to add up the previous two numbers to get the next one. This recursion lends itself very well to a for loop. f(x)=sin(x) and g(x)= x-1 over the range [0, 3]. Draw f(x) in To
% Generates a random number between 1 and 100 randNum E randi (100, 1) if randNum = G disp(['The number is' num2str(randNum) 'odd']); disp([ 'The number is' num2str(randNum) 'even']); else end % Write the if statements here
3. If statements: The code in the file generates a random integer between 1 and 100. Write an if 3. If statements: The code in the file generates a random integer between 1 and 100. Write an if statement to determine
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am