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

USING MATLAB ONLY - PLEASE COMMENT CODE IN DETAIL & SHOW OUTPUT Write an M-file.

ID: 3936399 • Letter: U

Question

USING MATLAB ONLY - PLEASE COMMENT CODE IN DETAIL & SHOW OUTPUT

Write an M-file.

Write Script M-file

Generate two arrays, A and B with the following values:

A(i) = 1/3 + i

B(i) = pi + i

where i = 1 to 10. You must use for loops to generate the arrays.

Now display headings and the arrays using fprintf as shown below. The i is decimal value of width 5; A a floating point value of width 6; and B a floating point value of width 7. Use the tab escape character to locate A and B. Again you must use for loops. Your output should be as follows:

    i A(i)        B(i)

------------------------

    1 1.333     4.1416

    2 2.333     5.1416

    3 3.333     6.1416

    4 4.333     7.1416

    5 5.333     8.1416

    6 6.333     9.1416

    7 7.333     10.1416

    8 8.333     11.1416

    9 9.333     12.1416

   10 10.333     13.1416

------------------------

Explanation / Answer

fprintf('i: A(i): B(i): ');
for i=1:10
A(i) = 1/3 + i;
B(i) = pi + i;
fprintf('%d %d %d ',i,A(i),B(i));
end