Question

In: Computer Science

USING MATLAB write a script that creates eight subplots(4x2). In each one, graph the values of...

USING MATLAB

write a script that creates eight subplots(4x2). In each one, graph the values of sin(n(pi)x), where -1 <=x<=1, with an interval of 0.05 for n = 1 to 8.

there is no parenthesis on pi. I just didn't want to make it look like (npix) so it wouldn't be confusing to read.

Solutions

Expert Solution

Following is the code in eight_sines.m :

%
% Define the x-vector.
% 
x = -1 : 0.05 : 1;

%
% We use a loop to draw the eight plots.
%
for n = 1 : 8
    
    %
    % Determine the y-vector.
    %
    y = sin(n .* pi .* x);
    
    %
    % Draw the plot.
    %
    
    % 
    % Choose the position.
    %
    subplot(4, 2, n);
    
    plot(x, y);
    title(['n = ', num2str(n),]);
    
    grid on;
    hold on;
    
end

Following is the run :

>> 
>> eight_sines
>> 


Related Solutions

Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three points A, B, and C, namely (xA, yA), (xB, yB), (xC, yC), forming a triangle, storing each in a variable (for a total of 6 variables). The script should then calculate the centroid G = (xG, yG) using xG = xA+xB+xC 3 and yG = yA+yB+yC 3 , storing each in a variable. Finally, the script should print all four points. Sample output: Enter...
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one...
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one vector v (either a column or a row) and outputs the same vector v of the same dimensions, but with the values in reverse order (use MATLAB function flip()). In other words, v will be overwritten by its flipped version. In your function, you may only use length() and floor(). You only need one loop. %this code tests the function, myflip, which you will...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
using matlab Write a script that simulates a card game that works as follows: A dealer...
using matlab Write a script that simulates a card game that works as follows: A dealer places 5 cards face down on the table and flips the first card. The player goes down the line, one at a time, and guesses if the next card is higher or lower than the card displayed, and then the next card is revealed. In the end, the player is awarded a point for each correct guess. In terms of coding, your script should...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer...
Write a MATLAB script file that will give the value of f(x) using method of least...
Write a MATLAB script file that will give the value of f(x) using method of least squares and asks the user to enter values of x, y, n (curve fit), and x for f(x).
Write a MATLAB script file that will give the value of f(x) using method of least...
Write a MATLAB script file that will give the value of f(x) using method of least squares and asks the user to enter values of x, y, n (linear, quadratic, or cubic), and x for f(x).
Write a script named numberlines.py. This script creates a program listing from a source program. This...
Write a script named numberlines.py. This script creates a program listing from a source program. This script should: Prompt the user for the names of two files. The input filename could be the name of the script itself, but be careful to use a different output filename! The script copies the lines of text from the input file to the output file, numbering each line as it goes. The line numbers should be right-justified in 4 columns, so that the...
USING MatLab (Arrays) Set ASIZE to 5. Write a program that creates an array of ASIZE...
USING MatLab (Arrays) Set ASIZE to 5. Write a program that creates an array of ASIZE numeric elements. Prompt the User for ASIZE numbers and store them in the array. After storing the values, calculate the sum of all the values in the array and display the sum. Modify the program you wrote for Problem 5 such that it calculates the product of all the values instead of the sum. Modify the program you wrote in Problem 6 such that...
Using Matlab, Write a script that validates the relationship between sin u, cos u, and tan...
Using Matlab, Write a script that validates the relationship between sin u, cos u, and tan u by evaluating these functions at suitably chosen values. Please screenshot Matlab screen. Thank you!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT