Question

MATLAB Homework 3- Due:5/20/2018 1. Create a function that receives the following input data, and prints the output as the summation of the diagonal elements (The elements which are located at the intersection of similarly numbered rows and columns) Input (Matrix A) Output (Scalar B) Example 2 -1 4 3 -45 ? B = A( 1,1) + A(2,2) = 2-4 =-2 A4 5 ?41 ? B = A(1,1) + A(2,2)--1-4-5 -3 1 1.5 -4 3.2 -1 06 1.78 2.22 -4.56 2. Create a function that receives the following input data (which are essentially the coefficients of a second de with increments of 0.1: gree polynomial, and plots the function in the interval 0 to 5 A, B, C Input (scalars) Output (plot) Plot Example A 2,B 3,C--1Plot 2x23x 1 forx [0:0.1:5 A =-4, B = 1,C = 1 ? Plot?4x2 + x + 1 for x = [0: 0.1 : 5]
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. The sample outputs are as follows :

Ex 1:

Ex 2:

Copy and run the following source code in MATLAB.

Source code:

function B=sum_diagonal(A)
B=0;
for i=1:min(size(A))
B=B+A(i,i);
end
end

2. The sample plots are as follows:

Ex 1:

Ex 2:

Source code:

function plot_polynomial(A,B,C)
x=[0:0.1:5];
y=A*(x.^2)+B*(x)+C;
  
plot(x,y);
end

Add a comment
Know the answer?
Add Answer to:
MATLAB Homework 3- Due:5/20/2018 1. Create a function that receives the following input data, and prints...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using matlab Write a function that receives a vector as an input argument and prints the...

    Using matlab Write a function that receives a vector as an input argument and prints the individual elements from the vector in a sentence format. One example of calling this function on the command window looks like >>printvec([1.12 23 9.245]) Element 1 is 1.12 Element 2 is 23.00 Element 3 is 9.25 1. (Note: your function should work for any vector.)

  • MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note:...

    MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note: input values are specified in the function call) Output: calculated maximum value Create a row vector A of values from 50 down to 0, with an increment of 0.5 Multiply the elements of A and the square of the elements of the input vector Store the results in B Find the maximum value of B and store it in C – this is the...

  • Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as...

    Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...

  • Without using the factorial command, create a code that receives a positive integer as the input,...

    Without using the factorial command, create a code that receives a positive integer as the input, and prints the reciprocal of its Factorial as the output Example: ?=4→??????=, -!= , -×0×1×,=, 1-=0.0417 Example: ?=2→??????=, 1!=, 1×,=, 1=0.5

  • Write a MATLAB function with the following specifications: Input parameter 1: A Input parameter 2: B...

    Write a MATLAB function with the following specifications: Input parameter 1: A Input parameter 2: B Input parameter 3: C Input parameter 4: D Output parameter: Sum of the input parameters Time interval: -2T lessthanorequalto t lessthanorequalto 2T Waveform 1 to plot: y(t) = A sin(B(t - c))+D Waveform 2 to plot: y(t) = A cos(B(t - c)) + D Display two plots in vertical fashion on one figure Include all labeling on both plots. Add a grid to both...

  • Matlab Homework #4: Matlab Linear Systems Simulation 1.) Obtain the differential equation for the...

    Matlab Homework #4: Matlab Linear Systems Simulation 1.) Obtain the differential equation for the mechanical system shown below bi FLR) orce CN) voltege ) 2.) Obtain the differential equation for the electrical system shown below shown below OAF 3.) Find the transfer functions corresponding to the differential equations found in questions I and 2 the 4) Let the input force applied to the block of the mechanical system be zero U)-のThe initial conditions are y(0) = 10 cm and dy(0)d-0....

  • c++ language 1) Create a function that prints a greeting when called with a name such...

    c++ language 1) Create a function that prints a greeting when called with a name such as greeting ("Elona") 2) Create a function that squares a double number and returns the result as a double. 3) Create a function that takes 5 int numbers and returns the average as a float 4) Create a single function that gives a greeting, calculates the average of 5 grades but does not return a value. Hint: Use return type void and a string...

  • This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an...

    This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an integer number n, and returns a matrix that is nxn, where the value of each number is the distance from the upper-left to bottom-right diagonal. (Use while loops if you can!) Numbers below the diagonal should be negative, and numbers above the diagonal should be positive. For example, if your input was 5, your output would be: 0 1 2 3 4 -1 0...

  • Define a function called collapse() which takes a list as input. Each element of the list...

    Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...

  • Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to...

    Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to symbolically compute the derivative of ln(x) on the interval from -5 to 5, containing 100 data points. Your script file should output a plot of the derivative of ln(x) (taken from your function) vs x. Use a line with circular markers for the plot and include a grid and appropriate labels. The user-defined function should 1. Receive a single x value as input. 2....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT