Question

MATLAB ProblemHW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the following math function 3 o-0.47x The input to the function is x and the output is y. Write the function such that x can be an array (use element-by-element operations) (15 pts) Use the function in (a) the command window to calculate y(-2) and y(5) (b) a script file HW7P2.m to determine y(x) for 0.001 Sx S 10 with 1000 points. Hint: Use the linspace function to create the x vector (c) In the same script file HW7P2.m, plot the function v(x) 4 times in 2 by 2 subplots using the following 1. 2. 3. 4. Linear scale for both the x and y axes Linear scale for the x axis and logarithmic scale for the y axis Linear scale for the y axis and logarithmic scale for the x axis Logarithmic scale for both the x and y axes Use the axis () function to adjust the limits of the x axis from the minimum value of x to the maximum value of x and the same for the y axis. You can use the functions min () andmax () in MATLAB after reading their help sections

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab code for the user defined function

===================

function y=HW7P2_fn(x)
y=0.6*(x.^3).*exp(-0.47*x)+1.5*(x.^2).*exp(-0.6*x); % calculate values for y
end

================

Matlab code for the script:

=================

x=linspace(0.001,10,1000); % generate x
y=HW7P2_fn(x); % call user function to calculate y
subplot(2,2,1) % add first plot in 2 x 2 grid
plot(x,y)
axis([min(x) max(x) min(y) max(y)]) % setting axes
subplot(2,2,2) % add second plot in 2 x 2 grid
semilogx(x,y)
axis([min(x) max(x) min(y) max(y)])
subplot(2,2,3)% add third plot in 2 x 2 grid
semilogy(x,y)
axis([min(x) max(x) min(y) max(y)])
subplot(2,2,4)% add fourth plot in 2 x 2 grid
loglog(x,y)
axis([min(x) max(x) min(y) max(y)])

=================

Output:

迥ム, G. Program Files·MATI AB-R2017 )反Editor-G:\Program Files\MATLAB\R2017a\HW7P2.m Command Window >HW7P2fn (-2) x-linspace (o

Add a comment
Know the answer?
Add Answer to:
MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the...
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
  • Problems in this assignment are to be done using MATLAB W7P2 (15 points) A High-Pass Filter...

    Problems in this assignment are to be done using MATLAB W7P2 (15 points) A High-Pass Filter passes signals with frequencies that are higher than a certain cutoff frequency. In this filter the ratio of the magnitudes of the voltages is given by: wRC where ω = 2nf is the frequency of the input signal Given R 2000 2 and C 0.2 x 10-6 F. Write one script file HW7P2.m to make four plots in four separate figures (Figures 1, 2,...

  • Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following...

    Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following math function with x the input argument and y the output y(x)=0.8x4-13x2-5x The function should work for x being a scalar or a vector. Write a script file named PBTask4pl.m to a) Use the function to calculate y(3) and y(5) and display the results in command window b) Use the function to make a plot of the function y(x) for -5:5: x 5:5. Label...

  • Please use matlab cars. Answer: Function file; Command Window: 5.4 Write a user-defined function that plots...

    Please use matlab cars. Answer: Function file; Command Window: 5.4 Write a user-defined function that plots a circle given the coordinates of the center and the radius. For the function name and arguments use circleplot(x,y,R). The input arguments are the and y coordinates of the center and the radius. Use linspace to generte the angle from 0 to π with 100 points. (Hint: the circle equation: x+Rcos and yy-yRsin 0.) This function has no output arguments. Plot the circle using...

  • B.1 Write a MATLAB user-defined function for interpolation with linear splines Name the function Yint =...

    B.1 Write a MATLAB user-defined function for interpolation with linear splines Name the function Yint = Linear Splines, y, rint), where the input ar- guments and y are vectors with the coordinates of the data points and rint is the coordinate of the interpolated point. The output argument Yint is the y value of the interpolated point. Also write a program in a script file that plots the data points and the curve of the Linear splines that interpolates the...

  • Write a MATLAB script that loads and displays each of the captured images. Publish the MATLAB...

    Write a MATLAB script that loads and displays each of the captured images. Publish the MATLAB script output as a .docx file. For compactness purposes, show all five waveforms for each case on the same figure using MATLAB subplots. Use the legend function in MATLAB to add appropriate labeling to the subplots to ensure that the Figure legend can be written succinctly.

  • Write a user-defined MATLAB function for the following math function y(x). The input to the function...

    Write a user-defined MATLAB function for the following math function y(x). The input to the function is x and the output is y. y(x)=-(0.2*x^4)+((e^-0.5*x)*x^3)+7*x^2 Call the function to calculate y(x) over the interval -3 ≤ x ≤ 4 for each increment of 1. Display x and corresponding y(x) in a text file with labeled column headings. Use the type command to display the contents in the text file.

  • MATLAB Only MATLAB Only MATLAB Only Indicated in the script below, write a function, called arbpoly3,...

    MATLAB Only MATLAB Only MATLAB Only Indicated in the script below, write a function, called arbpoly3, that accepts two inputs: i) a row vector, called c, containing the coefficients of the polynomial, starting with the coefficient for the lowest degree term, which is the constant term. ii) a row vector, called x, which is the set of real numbers where the polynomial is to be evaluated. The output, y, will be a vector containing the values of the polynomial, evaluated...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • please solve in matlab 1[35p) Write a user-defined MATLAB function that determines the unit vector in...

    please solve in matlab 1[35p) Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two points (A and B) in space. For the func- tion name and arguments, use n = unitvec (A,B). The input to the function are two vectors A and B, each with the Cartesian coordinates of the corre- sponding point. The output is a vector with the components of the unit vector Join the direction from A...

  • 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