Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this homework problem, and in all subsequent homework problems, you will part

ID: 3785916 • Letter: I

Question

In this homework problem, and in all subsequent homework problems, you will partition your script m-file into sections. There will be one section per problem. Because Homework 1 has two problems, your script m-file for this homework will contain 2 sections. Have MATLAB print (to the command window) the following: e in fixed-point notation to seven decimal places (plus a new line) e in exponential (scientific) notation with five decimal places (plus a new line) -256 in (signed) integer notation (plus a new line) In the above, e is the base of the natural logarithm. MATLAB will generate this number whenever you ask for this: exp (1). With this statement, you are asking for e You will use fprintf. You should first read the MATLAB documentation on the function fprintf. Pay particular attention to the forma portion of the documentation. (On the fprintf documentation page, click on the format hyperlink.) In this problem you won't be printing to a file, so you won't supply the optional fileID input. If you are familiar with the CC++ function printf, you will sce that the MATLAB fprintf function works in a similar way. The purpose of this assignment is for you to practice formatted printing of numbers. You are asked not to print pure literal strings. For example, don't do this: fprintf 2.7182818 n' Don't do this! It is true that this statement will produce the desired first line. However, you will not learn the formatted printing of numbers if you do this. Instead, you will ask MATLAB to print exp (1) using a total of 9 characters, 7 of which will be to the right of the decimal place. (There will also be I character to the left of the decimal place and the decimal point, making a total of9 characters) Use the function sum to do this problem. First, create the following matrix: [1 4 7 2 5 8 3 6 9]. From this matrix, create a row vector, each element of which is the sum of the elements in one column of the above matrix. For example, the first element in this vector should be12. Display this row vector. From this matrix, create a column vector, each element of which is the sum of the elements in one row of the above matrix. For example, the first element in this vector should be 6. Display this column vector. Calculate the sum of all elements in the matrix above and display this sum.

Explanation / Answer

1.answer:-

important:-

you have to type the following code(starting with symbol >>) in command prompt of matlab

e in fixed point notation:-

%4.7f in the formatspec input specifies that the first value in each line of output is a floating-point number with a field width of four digits, including seven digits after the decimal point and will make the next output to get next line

>> formatspec='the value of e is %4.7f ';

>> fprintf(formatspec,exp(1))
the value of e is 2.7182818

e in scientific notation:-

%4.5e in the formatspec2 input specifies that the first value in each line of output is a floating-point number with a field width of four digits, including five digits after the decimal point and it will specify that output should come in power's of e, will make the next output to get next line


>> formatspec2='the value of e is %4.5e ';
>> fprintf(formatspec2,exp(1))
the value of e is 2.71828e+00

   -256 in signed integer notation

functions to change a particular number x into signed integer are int8(x),int16(x),int32(x),int64(x)

we have to use fprintf function in the same way as we did for fixed point representation of e

8 bit signed integer notation:-
>> fprintf('the value of -256 in signed integer notation is %2.0f',int8(-256))
the value of -256 in signed integer notation is -128

16 bit signed integer notation:-
>> fprintf('the value of -256 in signed integer notation is %2.0f',int16(-256))
the value of -256 in signed integer notation is -256

32 bit signed integer notation:-
>> fprintf('the value of -256 in signed integer notation is %2.0f',int32(-256))
the value of -256 in signed integer notation is -256

64 bit signed integer notation:-
>> fprintf('the value of -256 in signed integer notation is %2.0f',int64(-256))
the value of -256 in signed integer notation is -256>>

2.answer:-

%first create a matrix b as given below

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

%use the sum function and give b as argument in it to add the elements column wise and store them in row vector as given below
>> rowvector=sum(b)

rowvector =

12 15 18

%give b' as argument in sum function to add the elements in matrix b' column wise and store them in row vector d as given below

>> d=sum(b');
%we can now convert row vector d into column vector by transposing it and store it in the variable columnvector
>> columnvector=d'

columnvector =

6
15
24

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote