Question

4. Write a code that will allow a vector of positive integers in x, as a user input, to evaluate the equation listed below (p

For Matlab
0 0
Add a comment Improve this question Transcribed image text
Answer #1
x = input("Enter a vector of numbers: ");
y = [];
for i=1:length(x)
    if mod(x(i), 2) == 0
        y(i) = 2*x(i)^2 - 8*x(i) + 3;
    else
        y(i) = 2*x(i)^2 + 8*x(i) - 3;
    end
end
disp(y)

[2, 3, 4, 5 Enter a vector of numbers: > -5 39 3 87

Add a comment
Know the answer?
Add Answer to:
For Matlab 4. Write a code that will allow a vector of positive integers in x,...
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
  • write a programming code for the following problem using Visual Basic Studio VB. Write a program that will allow the user to enter series of mumbers and will give some useful statistics about the mam...

    write a programming code for the following problem using Visual Basic Studio VB. Write a program that will allow the user to enter series of mumbers and will give some useful statistics about the mambers Enter Numbers Button Click-Allow the user to enter series of nambers using imput dialog boxes. Use a loop and add the numbers to the listBox as they are input.. Prompt the user to enter"x" to stop addang numbers. Compute Statistics Button Click-Compute the following statistics...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Write a script that will create a (random) vector of ages (real numbers, not integers). The...

    Write a script that will create a (random) vector of ages (real numbers, not integers). The script should contain the following prompts: - the user will provide the number of elements in the vector. - the user will provide the age of the oldest person in the group. For example: Enter the number of persons in the group: 50 Enter the age of the oldest person: 37 Save the vector containing the ages in a “.dat file” called ages_vector.dat matlab...

  • Matlab write a code that - Prompt a user to enter 2 positive numbers (check the...

    Matlab write a code that - Prompt a user to enter 2 positive numbers (check the that they are positives) - find the LCM - For each number test its multiplicity of 2 , 3 , 5 , 7 , 11

  • Write a MATLAB script that asks the user to enter a whole number (i.e., any whole...

    Write a MATLAB script that asks the user to enter a whole number (i.e., any whole number, positive, negative or zero). After the number is entered, the program must utilize an IF-ELSE statement and determine the parity of the number. The parity of a number is simply whether it is an even number or an odd number. If the number is even, MATLAB must then generate and display the message: The entered number is an even number. Otherwise, MATLAB must...

  • 2- Write a MATLAB code to visualize (2D) the electric field vector due to four equal point charge...

    2- Write a MATLAB code to visualize (2D) the electric field vector due to four equal point charges Q, Placed at vertices of a rectangle of length a and width w in free space. The code must ask the user to input the value of the charge and the size of the edges. 2- Write a MATLAB code to visualize (2D) the electric field vector due to four equal point charges Q, Placed at vertices of a rectangle of length...

  • integers between 5 and 400 Use MATLAB command windows to create a vector with all a)...

    integers between 5 and 400 Use MATLAB command windows to create a vector with all a) Ans) "deconv" Write a function integerdivision to divide two polynomials function using the command b) d) Write m-file to find the roots of the following linear equation using MATLAB x5 +2x -5x3 +7x2+12x +200 Ans) Questions 2 cover CLO2:/10 a) Write the output of the following MATLAB code >> A = [2,4,10,13:16,3,7,18; 8,4,9,25:3,12,15,171 >> length (A) >> size (A)

  • 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 code for this problem. 1[35pl Write a user-defined MATLAB function that determines the unit vector...

    Matlab code for this problem. 1[35pl Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two points (A and B) in space. For the func- tion name and arguments, use n = unitvec (A,B). The input to the function are two vectors A and B, each with the Cartesian coordinates of the corre- sponding point. The output is a vector with the components of the unit vector in the direction from...

  • 2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum...

    2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum of both of the integers and all the numbers in between Write a Marie program that determines the largest of a series of positive integers provided by a user. The user will enter a -1 when she is finished. Up to 10 numbers will be provided by the user. Write a Marie program that accepts two positive integers, multiples them by repeated addition, and...

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