Question

Using MATLAB code Assume you have a single row vector stored in a variable. You do...

Using MATLAB code

Assume you have a single row vector stored in a variable. You do not know how many elements are in the vector. Write your own code that sums all the elements in the vector. You are not allowed to use "sum" or any form of loops. (Hint: Use vector characteristics. It will be a single line code.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code for adding the elements in the vector

**************************************************

>> A = [1 2 3 4 5 6 7 8 9]

A =

1 2 3 4 5 6 7 8 9

>> norm(A,1)

ans =

45

*****************************************************

Steps:

# Assign a vector of any length A

# To add the elements in the vector using the command norm(A,1)

norm(A,1) takes the absolute value for each element in the vector and adds it.

Add a comment
Know the answer?
Add Answer to:
Using MATLAB code Assume you have a single row vector stored in a variable. You do...
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 Matlab Function (not a script) that performs a single iteration of the Euler's method...

    Write a Matlab Function (not a script) that performs a single iteration of the Euler's method for the regular parashot problem, (i.e. just write a function that calculates v_next) Assume: cd = 0.25 [kg/m] for t < 10sec and cd = 1.5   [kg/m] for t ≥ 10sec Hint: use only if-statements, do not use any LOOPs you only need to compute only one iteration Hint2: make sure you define the inputs and outputs of the function correctly Please show how...

  • MATLAB Onramp ASSIGNMENT: 2. Create a 1x15 (1 row, 10 columns) vector of random numbers (use...

    MATLAB Onramp ASSIGNMENT: 2. Create a 1x15 (1 row, 10 columns) vector of random numbers (use randn command “x = randn(1,10)). And do the following: a.Test vector x for elements that are less than 0.2. Assign the output to a variable named y. b.Create a variable z that contains the elements in x that are greater than 0.2. c. Modify vector x such that any value in it less than 0.2 is replaced by value 0.

  • Chapter 6 Matlab Assignment: Assume x is a row vector containing 100 elements. Write a counter-controlled...

    Chapter 6 Matlab Assignment: Assume x is a row vector containing 100 elements. Write a counter-controlled loop using a "for" command and an "if" command that examines one element of x each time through the loop. If that element is greater than 10, replace it with a random integer between 1 and 20. Chapter 7: Explain the use of functions in computational programs like the ones you wrote

  • Hello, can you do this in matlab full solution thanks Purpose: To practice using the MatLab...

    Hello, can you do this in matlab full solution thanks Purpose: To practice using the MatLab interface. practice with Matrix Arithmetic Operation. Degree of Difficulty: Easy After the fourth shinobi world war, it becomes a rule in Konoha that to be a jenin (the lowest level of ninja) from an academic student (ninja-student) anyone needs to get 1000 points. A student can earn points by finishing different missions. Below is a chart showing the individual mission points based on the...

  • Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in);...

    Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in); Random r = new Random(); Write code to do the following: Use a while loop to prompt the user for how many numbers are to be entered. If the user does not enter a positive number (a number greater than 0), display a message saying the number must be positive and to try again. Store this value in the howmany variable. Declare an integer...

  • Numerical Analysis Matlab Use single - variable method Write a matlab code to show how do...

    Numerical Analysis Matlab Use single - variable method Write a matlab code to show how do you run this algorithm Given the function ƒ(x) = sin(x) - e^x + 2 Find the minimum value in [a, b]=[-1, 3]. Starting from the leftmost end point and move toward to rightmost end point (i.e forth) with your first ∆x = (b - a)/4 = (3 - (-1))/4 = 1 Stop the iteration when your ∆x ≤ 0.01

  • please write the code on matlab   using for loop Also practice using for loops to combine...

    please write the code on matlab   using for loop Also practice using for loops to combine two vectors with the same number of elements. do in-between iterations one before the last iteration will have w/index=(last element-1)) = 4x(index=(last_element-1)) - 2(2) last iteration windex=last element)= 4*x[index=last element) - z(1) you need to figure out how to the change in index for vector z within the for loop.

  • The problem below is a MATLAB question, please do it only Matlab, if you are not...

    The problem below is a MATLAB question, please do it only Matlab, if you are not familiar with Matlab or not equipped with the program itself on your computer kindly leave it to someone who is. Please show me the Matlab codes for these two parts of the problem, I need to put them in same (m.file) so please consider that. Either you type the code or "preferably" you take a snip of your screen and post to teach me...

  • Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts...

    Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...

  • You will write a program in C that multiplies a matrix by a vector, using MATLAB...

    You will write a program in C that multiplies a matrix by a vector, using MATLAB to check the results. Create a program in MATLAB to solve the Topic 5 "File I/O" assignment. Use any built-in MATLAB functions of your choice. Some might require you to change your input files slightly; if so, document what you did and explain why. Compare and contrast the C and MATLAB versions of your code. works in matlab

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