Question

computer Question 3 (3) The mod function can be used to determine if a number is odd or even. The modulus-2 of an odd number is 1, and the modulus-2 for an even number is a. See the Code below. >mod,2) med(6,2) Write a Matlab script that uses a for loop and an if statement to sum up the odd values in thie vector a Paste the image of your handwritten code héte Screenshot of Code here Write the Numerical Answer here
0 0
Add a comment Improve this question Transcribed image text
Answer #1

,,5,3,5,6,1,3,, 6,4,2,3 Sum:0; for : numel (x) if mod(X(i),2) Sum sun() en umtx end Explanaton o cade a variable sum and nitialrze it to o numel)- gives the no. of elements ih vector ake Rum he or loc P from element to as, elemen- > mod (k,2) if k s odd it gives 1 we have Ho find odd number So wite t in if conditon If number is odd it enters the conditton loop. Then we add that rumbey eleee elee we dorat add itANSWER=27

Add a comment
Know the answer?
Add Answer to:
computer Question 3 (3) The mod function can be used to determine if a number is...
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
  • Problem 3 (13 pts): (modified from Attaway Problem 3.39) a) (5 pts) Using the Matlab rand () func...

    Problem 3 (13 pts): (modified from Attaway Problem 3.39) a) (5 pts) Using the Matlab rand () function, create a script that generates a row vector (1 row X 20 columns) of random numbers, each with magnitude between 0 and 5 b) (3 pts) Use the round() function to turn all of the values into whole numbers by rounding down (truncate the decimal part on your vector) c) (5 pts) Add code to your script to generate a new vector...

  • mathlab please copy and paste the code and output Q1. (50 points) Consider the following mathematical...

    mathlab please copy and paste the code and output Q1. (50 points) Consider the following mathematical sequence for any mumber fathe sequence, the first number is 1 = 0. The remaining terms are computed via the following method. The second number of the sequence is given by 1 /2 f iseve Ty - 3x + 1 if, is add The third number of the sequence is given by 1 /2 fils even 133ry + 1 ifr, is odd Thus, the...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • MATLAB Question: Write a script for the problem pictured. Please send the script, not just the...

    MATLAB Question: Write a script for the problem pictured. Please send the script, not just the printout. Make sure your script allows you to input a value for n so when prompted, in the command window, user types n value. The n value should be the f_k if k ==1 .... Please also send print outs if you can. BELOW IS A SAMPLE ANSWER THAT DID NOT PUT THE INPUT SCRIPT NEEDED FOR THIS QUESTION TO BE CORRECT. YOU CAN...

  • The matlab code for the following problem is appreciated!! QUESTION 3 Write a function fnfr_plot that...

    The matlab code for the following problem is appreciated!! QUESTION 3 Write a function fnfr_plot that will receive two function handles from elementary math functions which accept a vector to first sort in ascending order then calculate. The script will display the results in two separate Figure Windows with the function names in the title. Submit: fnfr_plot.m Browse My Computer Attach File QUESTION 4 Generate 1x100 random vector, x in the range of 0<x<100 by using rand. Input 2 elementary...

  • Im not sure if this site uses MATLAB, but ill post the question anyway. MidPoint Rule...

    Im not sure if this site uses MATLAB, but ill post the question anyway. MidPoint Rule In this phase, we will evaluate the integral numerically using the definition by Riemann sum. For numerical calculations, we will use MATLAB software 3. First, use MATLAB to evaluate this time a definite integral x ехах For that, type directly into command window in MATLAB: syms x; int(x*exp(x),0,2). Get the answer in a number with at least four decimals. . Download an m-file, midPointRule.m,...

  • Question is two parts In R(Programming language). Define and write a function which takes one number...

    Question is two parts In R(Programming language). Define and write a function which takes one number as input and detects whether the number is even. Return TRUE if it is even, and FALSE otherwise. You need to first detect if the input is an integer; if not, return NA. Note 1: TRUE and FALSE are logical values, not strings! Note 2: No need to get user input from the console. Test your function using your_function_name(1), your_function_name(2), and your_function_name(1.5). Hint: What...

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • Matlab problem A vector, x, containing values between 0 and 5 is generated randomly below. %...

    Matlab problem A vector, x, containing values between 0 and 5 is generated randomly below. % the length of x is also determined at random. % set up a "for" loop to run over all elements of x - use the "length" command % inside the "for" loop, use a "switch" construct to find the odd values % and the even values (including zero) - use two "case" commands inside the "case" for the odd values, use an "if" so...

  • 1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers...

    1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers of 1 through 15. Display your result back to the user with 2 decimal places (yes, 2 decimal places). You must implement your code using a for loop. The result should have the following format: The multiplication of 10*1 =10.00 The multiplication of 10*2 =20.00 The multiplication of 10'3=30.00 The multiplication of 10*15=150.00 2. (35 Points) Write MATLAB code to prompt a user for...

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