Question

3. [20 points] Write a simple Matlab for-loop that adds up the squares of the elements of a vec tor V of length N. Variable S
0 0
Add a comment Improve this question Transcribed image text
Answer #1
V = [3 9 1 7 5]
% Assuming that V is already declared and assigned a value.
% so, ignore above statements(which is used for testing)

SumOfV = 0;
for i=1:length(V)
    SumOfV = SumOfV + V(i)*V(i);
end
SumOfV

V = - 3 7 1 7 5 SumofV = 165

Add a comment
Know the answer?
Add Answer to:
3. [20 points] Write a simple Matlab for-loop that adds up the squares of the elements...
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
  • Solve using Matlab Write a simple loop to list the squares of the first 10 integers....

    Solve using Matlab Write a simple loop to list the squares of the first 10 integers. Using a simple "while" loop, write a script to sum the series 1 + 2 + 3 + ... such that the sum is as large as possible without exceeding 100. The program should display how many terms are used in the sum. Write a script that takes as input an integer n and creates the n*n matrix A with (ij)th component given by...

  • write matlab script 5. Use a for loop to sum the elements in x = [1...

    write matlab script 5. Use a for loop to sum the elements in x = [1 2 3 4 5] Check your answer with sum function 6. Use a while loop to sum the elements in x = [1 2 3 4 5] Check your answer with sum function

  • Flowcharts & for loops 1. Using a for loop, write a MatLab script to convert ounces...

    Flowcharts & for loops 1. Using a for loop, write a MatLab script to convert ounces to grams for 0 to 16 ounces, in 1-ounce increments. Present output in a table; label columns appropriately. 2. A Fibonacci sequence is composed of elements created by adding the previous 2 elements. The simplest Fibonacci sequence starts with 1, 1 and proceeds as follows: 1,1,2,3,5,8… Element 3 is the sum of elements 1 and 2 (1+1=2) Element 4 is the sum of elements...

  • can anyone help me solve these on MATLAB?? please intro to programming and computation 3. 50...

    can anyone help me solve these on MATLAB?? please intro to programming and computation 3. 50 points - The purpose of this question is to test your ability to write for loops, so you won't get points if your answer works without using for loop. A vector is given by V - (5. 17. -3,8,0,-7. 12, 15, 20. -6, 6, 4.-7.16). Write a program as a script file that doubles the elements that are positive and raise to the power...

  • MATLAB QUESTION function Huge_Add = huge_add(number1,number2) sum= number1 + number2; sprintf(' %+5.2d',sum) end 3. Write function...

    MATLAB QUESTION function Huge_Add = huge_add(number1,number2) sum= number1 + number2; sprintf(' %+5.2d',sum) end 3. Write function called huge add that adds together two positive integers of any length specified as strings using decimal notation. The single output argument is the result and it is a string as well. The inputs and output must contain digits only; no commas, spaces or any other characters are allowed. If any of these assumptions are violated by the input, the function returns the number-1.

  • Create a new function file and write a function s= SUM_EVEn_ ubitname(V) that takes a vector...

    Create a new function file and write a function s= SUM_EVEn_ ubitname(V) that takes a vector V of arbitrary length and determines the sum of the even element and assign it to s. your function calculations must do the following: * Use a loop that iterates through every element of V and adds s only even element and skips all other elements. * Contain the appropriate H1 and help text lines. * Note: A number is even, if round(number/2) is...

  • Set up a vector n with elements 1, 2, 3, 4, 5. Use MATLAB array opera-...

    Set up a vector n with elements 1, 2, 3, 4, 5. Use MATLAB array opera- tions on it to set up the following four vectors, each with five elements: (a) 2, 4, 6, 8, 10 b)

  • MATLAB EXPERT PLS HELP!!! SHORT AND SIMPLE QUESTIONS! Just write the code to do the following...

    MATLAB EXPERT PLS HELP!!! SHORT AND SIMPLE QUESTIONS! Just write the code to do the following operations step by step please. You dont need background info on the question Prompt the user to enter x and if x is less than 2 or not an integer, use a while loop to display “Invalid!” and prompt the user to re-enter valid entries. Prompt the user to enter y as a vector of x elements. If the user did not enter in...

  • 1. Write a function in matlab platform for each part as described. a. Obtains the multiplication of elements of n-sized...

    1. Write a function in matlab platform for each part as described. a. Obtains the multiplication of elements of n-sized vector, where n is a positive integer. Name of this function must be “all2”. b. Obtains the sum of elements of nxn-sized matrix, where n is a positive integer. Name of this function must be “will3”. c. Obtains the sum of prime factors of an integer. Name of this function must be “be0”. Example (1): Prime factors of 84 are...

  • 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