Please I need help with solving this Matlab Homework 1- What is the output? Cons
ID: 1766857 • Letter: P
Question
Please I need help with solving this Matlab Homework
1- What is the output? Considering the order of precedence show step by step how each operator does the calculation. (as we discussed in class)
>> round((2^2+1+1)(2*3^2+2)+rem(7,2)+ceil(3+2/2))
2- Write a single command (Do not type the matrix elements explicitly. You can only use built in functions), which outputs the following matrix A: A = 4 3 3 3 3 4 3 5 3 3 4 7 1 2 3 4 >>
3- What is the output of the following command? if there is any error, explain why? >> B=[[1:2:8;linspace(1,4,4)];2:5]
4- What is the output of the following command in command window? Include your double arrows. >>Height=5.2; >>Weight=75.2; >>fprintf('My Height is %1.2f feet and my Weight is %.2f pounds',Height,Weight)
Output:
5- Write a few lines of MATLAB commands to swap the first and second rows of the following matrix D. Try to swap them with the minimum possible commands.(Do not type the matrix elements explicitly) D = 1 2 3 4 5 6 7 8 9
6- Write a one single MATLAB command which can plot the following two graphs (y vs. x and z vs. x) on the same plot >> x=[1 2 3 4 5]; >> y=[10 20 30 40 50]; >> z=[5 15 20 25 30 35];
Answer: >>
7- Write a polar plot command with the following angle and radius requirements: angle: from /2 to 2 which has 100 points. radius = cosine of the ‘angle’ times two The plot is solid line The plot is yellow color The plot has circle marker >> Find error(s) in the following MATLAB commands (if any):
8- The following is a one line statement typed in command window: clc,clear time=0:100; height=2^time/2; height Answer: 3
9- Which of the following is correct? If A and B are a [2x3] and a [3x4] matrix respectively?
a) A*B is a [2x3] matrix
b) A* A is a [2x3] matrix
c) B .* B is a [3x4] matrix
d) A .* B is a [2x4] matrix
10- What format can create the following output for >> 290/7? Consider the spacing between the lines also. >> format ??? >> 290/7
ans = 41.4286
Explanation / Answer
1-
>> round((2^2+1+1)(2*3^2+2))
ans =
2
>> rem(7,2)
ans =
1
>> ceil(3+2/2)
ans =
6
>> round((2^2+1+1)(2*3^2+2)+rem(7,2)+ceil(3+2/2))
ans =
9
3-
>> [[1:2:8;linspace(1,4,4)];2:5]
ans =
1 3 5 7
1 2 3 4
2 3 4 5
4-
The output is
My Height is 5.20 feet and my Weight is 75.20 pounds>>
5-
Matrix D given is having only one row. So, it is not possible to swap first and second row
6-
plot(y,x)
hold on
plot(z,x)
7-
angle=linspace(pi/2,2*pi,100);
radius=2*cos(angle);
plot(angle,radius)
plot(angle,radius,'y')
plot(angle,radius,'o')
8-
Code is wrong as "time" is a vector and it will give height in a vector form of same length
9-
c) B .* B is a [3x4] matrix
It will multiply B with its own elements and give a 3X4 matrix
10-
>> 290/7
ans =
41.4286