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

Continue working with for-end statements, focusing mostly on nested for-end stat

ID: 3811088 • Letter: C

Question

Continue working with for-end statements, focusing mostly on nested for-end statements. In a script file named LASTNAME_LAB9_ TASK1.m, write a program according to the following specifications. Unless specified, suppress all MATLAB Command Window output. After completing the program, the result of executing your program should look similar to the output shown below. Clear the MATLAB Workspace and the MATALB Command Window Create a variable named x and assign to it a row vector whose elements have equally spaced values starting with -0.5, ending with +2.0, with an increment of le-5. Create a variable named y and assign to it a row vector whose elements are obtained by evaluating function y(x) = 6e^1.5x cos (81 pi x) for each element contained in row vector X. Create a variable named F0 and assign to it a scalar value obtained by prompting the user with the prompt Enter a value of F0 for the line f(x) = F0: Plot y vs. x and F0 vs. x an axis contained within a Figure Window named Figure 1. Color the curve of y vs. x in red and the curve of FO vs. x in blue. Hold the current plot and turn on the major grid axis lines so as to more easily visualize the resulting curves. Define a for-end statement with a loop variable named k that will represent the indices/positions of row vector y. In the body of the for-end statement, perform the following: Count the number of times y(x) crosses the line f(x) = Fo. Use built-in text() function to draw a left arrow that "points" to each data point at which y(x) crosses the line f (x) = F_0. T he syntax is text (xPos, yPos, leftarrow') Use the built-in fprintf() function to display the value of each x wherein y(x) crosses the line f(x) = F_0. Format each value of x as a fixed-point real number showing a maximum of 3 digits beyond the decimal point. Using the built-in fprint0f() function, display the number of times y(x) crosses the line y(x) F_0. Format the number as an integer. Test your script with the following scalar values for F0: +20, -12, +5, -0.5, and 0.0. For each value of F0, visually verify the results generated in steps (f) through (g) with those generated in step (e).

Explanation / Answer

MATLAB CODE:

1. clear matlab workspace- use clear command

clear command window- use clc command

2. x = linspace(-.5,2,(2.5/e^(-5))) ##starting value=-.5,ending value=2,number of elements= range/e-5

or x= [-.5:e^(-5):2] ##372 values in between -.5 to 2 (1 x 372 matrix)

3.

## splitted into two 6e-1.5x and cos 8pi*x computed and store the results in y1 and y2

##obtained y using multiplying

y1 = 6*(e.^(-1.5*x))
y2= (cos(8*3.14*x))
y=times(y1,y2) ## element by element multiplication

4.

prompt = 'Enter a value of F0 for the line F(x))';
F0 = input(prompt)

total code:

x= [-.5:e^(-5):2]
y1 = 6*(e.^(-1.5*x))
y2= (cos(8*3.14*x))
y=times(y1,y2)
prompt = 'Enter a value of F0 for the line F(x))';
F0 = input(prompt)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote