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

create a function in MATLAB that has one input. no outputs will be returned. The

ID: 3710553 • Letter: C

Question

create a function in MATLAB that has one input. no outputs will be returned. The input will be vector, and the function should compute the square of each element of the input vector. This function should print the input numbers in the first column and their squares to the command window in two columns, with the input numbers in the first column and the squares in the second column. Both columns should have right justification. (in other words, the least significant digits should line up vertically). All numbers should be printed as integers. This script should create a vector of even integers, starting at 2 and ending at 34. Call your function with this vector as input.

Explanation / Answer

CREATE vector_square.m AND PASTE BELOW CODE

function vector_square(A)
A_sq = A.^2;
temp = [A;A_sq]';
fprintf('%d %d ', temp.');
end

CREATE test.m AND PASTE BELOW CODE

close all
clear all
clc

A=2:2:34; %CREATE ARRAY OF EVEN NUMBERS
vector_square(A) %CALLING FUNCTION

PLEASE RUN test.m AND YOU WILL GET BELOW OUTPUT

2 4

4 16

6 36

8 64

10 100

12 144

14 196

16 256

18 324

20 400

22 484

24 576

26 676

28 784

30 900

32 1024

34 1156

>>