Question

In the code space provided in Matlab Grader, create a function that:

1. Accepts an input matrix A as its only input argument. Matrix A is a 3x3 matrix of random integers between 1 and 4

2. Produces and output matrix B as its only output argument. Matrix B will also be a 3x3 matrix.

3. Calculates the elements of matrix B such that: a. the values of B along the diagonal are equal to the respective elements in A b. the values in each element of B not along the diagonal are equal to the sum of the values in the respective row and column of A

Use for loop.

Answer #1

**The function is as follows**

function B = matrixAB(A)

for i =1:3

for j = 1:3

if i==j

B(i,j)=A(i,j); % the values of B along the diagonal are equal to
the respective elements in A

else

B(i,j) = sum(A(i,:))+sum(A(:,j)); % the non diagonal values in B
are equal to the sum of the values in the respective

% row and column of A

end

end

end

end

To get a matrix of random integer values between 1 and 4, we can use

A = randi([1 4],3,3)

where 1 and 4 are the range, 3 and 3 is the number of rows and columns of the matrix required

To check the function, first generate the matrix using the command

A = randi([1 4],3,3)

Now call the function

B = matrixAB(A)

**Example Output**

>> A = randi([1 4],3,3)

A =

3 3 1

4 3 2

2 1 4

>> B = matrixAB(A)

B =

3 14 14

18 3 16

16 14 4

>>

Create a function x=backsub(U,y) in matlab that accepts as
input
arguments a nxn matrix U and n-vector y, and returns as output a
column vector x
consisting of the values of the unknowns x1; x2; : : : ; xn.

using matlab:
Q)using nested for loops to generate a 3*3 matrix where the
element value is equal to the sum of its row and column number,
except for the diagonal elements which are zeros

*** Write a function called reverse_diag that creates a square
matrix whose elements are 0 except for 1s on the reverse diagonal
from top right to bottom left. The reverse diagonal of an n-by-n
matrix consists of the elements at the following indexes: (1, n),
(2, n-1), (3, n-2), … (n, 1). The function takes one positive
integer input argument named n, which is the size of the matrix,
and returns the matrix itself as an output argument. Note that...

MATLAB:
Write a function called matrix_problem1 that
takes a matrix A of positive integers as its sole input. If the
assumption is wrong, the function returns an empty matrix.
Otherwise, the function doubles every odd element of A and returns
the resulting matrix. Notice that the output matrix will have all
even elements. For example, the call B = matrix_problem([1 4; 5 2;
3 1], will make B equal to [2 4; 10 2; 6 2]. The function should
work...

Please write the code
in Python.
Write a
program/function in any Object-Oriented programming language that
will implement Queue Abstract Data Type with the following
functions/methods. Any build-in/pre-defined Queue
function/library (e.g., java.util.Queue in Java) is
NOT allowed to use in your code.
push(Element): insert the
input Element (e.g., String or Integer in Java) to the end
of the queue.
pop(): remove
the head element of the queue and print the head element on
screen.
count(): return the total number of
elements in the queue...

Part 2: Solve the following problems in
MATLAB
1. Fill in the function E = myElim(A, r_entry, r_pivot, c) to
create an m by m
elimination matrix ??. Remember that
an elimination matrix looks like an identity matrix with one extra
entry of ?? in row r_entry and column r_pivot.
2. Fill in the function M = myMult(A, c_pivot) to create an m by
m multiplier matrix ??. Remember that a multiplier matrix looks
like an identity matrix with the...

Questions:
1. Create a VB.NET Console Application that defines a
function Smallest and calls this function from the main program.
The function Smallest takes three parameters, all of the Integer
data type, and returns the value of the smallest among the three
parameters. The main program should
(1) Prompt a message (using Console.WriteLine) to ask the user to
input three integers.
(2) Call the built-in function Console.ReadLine() three times to
get the user’s input.
(3) Convert the user’s input from...

Write a MATLAB function and test bench script code to solve the
above simple RL/RC circuits by following the instructions noted
below. The input signal and impulse response generation should be
done in the function. The test bench script should be used only to
call the function and for signal plotting purposes. No plotting
should be done inside the function itself. Name your function
L2_C
Instructions: Input voltage ,x(t), can be AC or DC. Consider a
variable ‘w1’ which can...

Problem 3 you can use Matlab and also i give u the Problem 1
code its on Matlab
Using the same initial code fragment as in Problem 1, add code
that calculates and plays y (n)=h(n)?x (n) where h(n) is the
impulse response of an IIR bandpass filter with band edge
frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth
prototype. Name your program p3.sce
this is the Problem 1 code and the solutin
clear; clc;...

Curve-Fit Function USING MATLAB
Using the top-down design approach, develop a MATLAB function
A8P2RAlastname.m that reads data from a file and performs
regression analysis using polyfit and polyval. The function shall
have the following features:
The input arguments shall include the file name (string), a
vector of integers for the degrees of polynomial fits to be
determined, and an optional plot type specifier (‘m’ for multiple
plots, ‘s’ for a single plot - default).
The data files will be text...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 14 minutes ago

asked 26 minutes ago

asked 39 minutes ago

asked 50 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago