Write the matlab code to set up the vector

Assignment Help MATLAB Programming
Reference no: EM13856192

Objectives

The objectives are to introduce the following concepts:

• vector element access

• compound conditional statements

• pie charts

Deliverables

Submit your pre-lab answers in Bb Learn under the Lab 6 pre-lab assignment area prior to the start of class

1. We can access certain elements of a vector by specifying the index of the value we want in parentheses after the vector's name. Suppose we have a vector x = [1 5 3 6 3]. We would type x(2) to get the second value in the x vector or x(4) to get the fourth value in the x vector. If we want to multiply the fifth value in the x vector by 3, we would write x(5) = x(5) * 3.

Write the MATLAB code to add 1 to the third element of the x vector.

2. We can check for more than one condition in an if statement or while loop with the use of logical operators. The logical AND (&&) operator connects two Boolean values. If both of the Boolean values are true, then the expression returns true. Otherwise, the expression returns false. The logical OR (||) operator also connects two Boolean values. If either of the Boolean values are true, then the expression returns true. Otherwise, the expression returns false. Note that compound conditional operators can be chained together to make complex expressions.

i) The following would execute the code inside the while loop as long as a is greater than 7 or b is greater than 9. The code inside of the while loop adjusts the values of a andb so that there is not an infinite loop.

a = 14;
b = 12;
whilea>7 || b>9
a = a - 2;
b = b - 1;
end

Suppose we have a variable calledc, which represents some integer. Write the MATLAB code for a while loop that executes as long as c is greater than 4 or c is less than 11. Just show the while loop line. You do not need to include any code inside of the while loop.

ii) The following code would execute the code inside the while loop as long as d equals the character ‘u' and e equals the character ‘v'. The code inside the while loop asks the user for input to update the values of d and e.

d = input(‘Enter a value for d', ‘s');
e = input(‘Enter a value for e', ‘s');
while d == ‘u' &&e == ‘v'
d = input(‘Enter a value for d', ‘s');
e = input(‘Enter a value for e', ‘s');
end

Suppose we have a variable called f, which represents a character. Write the MATLAB code for a while loop that executes as long as f does not equal ‘u' and f does not equal ‘v'. Recall that MATLAB uses ~= to check if two values are not equal. Just show the while loop line. You do not need to include any code inside of the while loop.

3.The following links provide information on the pie, legend, and title commands.

https://www.mathworks.com/help/matlab/ref/pie.html
https://www.mathworks.com/help/matlab/ref/legend.html
https://www.mathworks.com/help/matlab/ref/title.html

Write the MATLAB code to set up the vector y = [2 4 3 6 2] and plot y in a pie chart. Add a legend and title to the pie chart. The legend should contain the following strings: ‘value1', value2', ‘value3', ‘value4', and ‘value5'. The title should be ‘My Awesome Pie Chart'.

Reference no: EM13856192

Questions Cloud

Compare and contrast cea cua and cba : Compare and contrast CEA, CUA, and CBA. Find an article that discusses a program evaluation where at least one of these was used
Explain the researcher role in qualitative research : Explain the researcher's role in qualitative research. Discuss the unique issues that researchers should be concerned about in regards to their role in research, and explain how this is specifically a challenge in ethnographical research
Which is the true concerning bond covenants : Which of the following is true concerning bond covenants? When considering defined benefit pension plans, which of the following will not increase the projected benefit obligation (PBO)?
How much did the company collect in cash from debtors : How much did the company collect in cash from debtors during 2006? How much sales would have been reported by the company in 2006 if Byfort would have been using cash accounting and not accrual accounting?
Write the matlab code to set up the vector : Write the MATLAB code to set up the vector y = [2 4 3 6 2] and plot y in a pie chart. Add a legend and title to the pie chart. The legend should contain the following strings: ‘value1', value2', ‘value3', ‘value4', and ‘value5'. The title should b..
What is the source of china new power : Write a 700- to 1,050-word paper, addressing how China is adapting its culture while facing tremendous economic development. What is the source of China's new power? How has history prepared China for its role as a political leader
What is your estimate of price per share : What is your estimate of price per share using the dividend discount model at 12/31/05? What is your estimate of price using the residual income valuation model at 12/31/05?
How technology has influences in humans connection : Sociology research paper- My topic : how technology has influences in human's connection/ communication.
Conduct online research to find out more information : Conduct online research to find out more information

Reviews

Write a Review

MATLAB Programming Questions & Answers

  Develop matlab function for the fixed-point method

Develop your own Matlab function for the Fixed-point method. Use the estimated relative error as your stopping criterion. The first line of your function should be function

  What is the difference between a script and function

Learn how to use various MATLAB built-in functions, What is the difference between a script and function? How do you create a new script or function in MATLAB

  Matlab function to perform gauss-jordan elimination

Write a matlab function to perform gauss-jordan elimination with pivoting. Modify the pivoting so that it is using the row with the highest absolute value rather than the first non-zero row.

  Write a script to solve the problems using vector operations

Write a script to solve the subsequent problems using only vector operations - Assume you have two vectors named A1 and B1 of equal length and create a vector C1 that combines A1 and B1 such that C1 = [A1(1) B1(1) A1(2) B1(2) . . . . A1(end) B1(end..

  Write a simple program that stores the high temperatures

A meteorological company wants you to write a simple program that stores the high temperatures and low temperates for each of the months of the year. After consulting with trusted programming partners, you come up with a great idea

  Considered to equal when the result of one array subtract

Two arrays are considered to be equal when the result of one array subtracted from the other is an array of zeros. In the script file, create the MATLAB commands to prove the following relationships (use arrays that you makeup yourself)

  Construct a commutated dc motor to drive a load

Construct a commutated DC motor to drive a load, simulated by a generator placed on the output shaft of your motor. You may use any readily available materials - characteristic for the different field densities created by the different permanent ma..

  Make a program that will graph the parabolas

Make a program that will graph the parabolas each parabola a different color and put all the parabolas in the same figure or graph

  Compute the power spectral density vector

Compute the power spectral density vector. Plot the spectrogram using the same parameters as in lecture.

  Matlab program to compute how much money will accumulate

Write a MATLAB program to compute how much money will accumulate in 5 years in the account and in any CDs you buy. Run the program for two different savings interest rates: 4 percent and 5 percent.

  Find the potential energy stored in each spring

The potential energy stored in a spring is kx2/2, where k is the spring constant and x is the compression in the spring. The force required to compress the spring is kx. The following table gives the data for five springs:

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd